0

我正在尝试使用 Constant Contact API 将新联系人添加到邮件列表。我有一个简单的 asp.net 表单并正在执行以下函数,但我得到“远程服务器返回错误:(403)禁止。” 我的功能直接来自Constant Contact,但请看图!

持续联系 API

Public Function AddContact(ByVal UserEmailAddress As String, ByVal ContactListNumber As Integer) As String
    Try
        Dim xml As String
        xml = "<?xml version='1.0' encoding='utf-8' ?>" & _
        "<entry xmlns='http://www.w3.org/2005/Atom'>" & _
            "<title type='text'></title>" & _
            "<updated>2008-07-23T14:21:06.407Z</updated>" & _
            "<author></author>" & _
            "<id>data:,none</id>" & _
            "<summary type='text'>Contact</summary>" & _
            "<content type='application/vnd.ctct+xml'>" & _
                "<Contact xmlns='http://ws.constantcontact.com/ns/1.0/'>" & _
                    "<EmailAddress>" & UserEmailAddress.ToString() & "</EmailAddress>" & _
                    "<OptInSource>ACTION_BY_CONTACT</OptInSource>" & _
                    "<ContactLists>" & _
                        "<ContactList id='http://api.constantcontact.com/ws/customers/[username]/lists/" & ContactListNumber.ToString() & "'/>" & _
                    "</ContactLists>" & _
                "</Contact>" & _
            "</content>" & _
        "</entry>"

        ' Set up the request
        Dim request As HttpWebRequest
        request = WebRequest.Create("https://api.constantcontact.com/ws/customers/[username]/contacts/")
        Dim byteData As Byte() = UTF8Encoding.UTF8.GetBytes(xml.ToString())
        request.Method = "POST"
        request.ContentType = "application/atom+xml"
        request.ContentLength = byteData.Length
        request.Credentials = New NetworkCredential("[api key]%[username]", "[password]")

        ' Send the request
        Dim postStream As Stream
        postStream = request.GetRequestStream()
        postStream.Write(byteData, 0, byteData.Length)

        Dim response As HttpWebResponse
        response = request.GetResponse()

    Catch ex As WebException
        Return ex.ToString
    End Try
End Function
4

1 回答 1

0

403 error for constant contact表示密码错误,或者密码字符串配置错误。他们指定[your_api_key]%[your_constantcontact_username]:[password]他们的身份验证。尽管他们说这已被弃用,但现在每个人都应该迁移到 oauth 2.0(或至少在 2013 年之前)。这样您就不必再传递密码了。

于 2012-11-09T02:21:38.557 回答