Archived Forum Post

Index of archived forum posts


Twitter Pin Oauth not working

Jul 08 '13 at 08:03

I'm not sure what I'm doing wrong. Part 1 works for me with no problem I take my "he-PIN-obtained-from-Step1" and plug it in on part 2 and I get a 401 error. I'm using the ActiveX version. I don't know if it has anything to do with Twitter changing it's api or not.


Here's the code and the lasterrortext with my codes removed

Dim http As New ChilkatHttp
Dim success As Long
'  Any string unlocks the component for the 1st 30 days.
success = http.UnlockComponent("Anything for 30-day trial")
If (success <> 1) Then
    Text1.Text = Text1.Text & http.LastErrorText & vbCrLf
    Exit Sub
End If

http.OAuth1 = 1 http.OAuthConsumerKey = "my-consumer-key" http.OAuthConsumerSecret = ""my-consumer-secret" http.OAuthVerifier = "the-PIN-obtained-from-Step1"

Dim req As New ChilkatHttpRequest Dim resp As ChilkatHttpResponse Set resp = http.PostUrlEncoded("", req)

If (resp Is Nothing) Then Text1.Text = Text1.Text & http.LastErrorText & vbCrLf Exit Sub End If

If (resp.StatusCode = 200) Then 'this is where I get a 401 error

'  Get the access token and secret:

Dim oauthToken As String
oauthToken = resp.UrlEncParamValue(resp.bodyStr, "oauth_token")
Text1.Text = Text1.Text & "Access token = " _
     & oauthToken & vbCrLf

Dim oauthTokenSecret As String
oauthTokenSecret = resp.UrlEncParamValue(resp.bodyStr, "oauth_token_secret")
Text1.Text = Text1.Text & "Token secret = " _
     & oauthTokenSecret & vbCrLf

'  Your application may now perform operations on the
'  Twitter account for whatever has been authorized.
'  To do so, prior to sending the HTTP request,
'  set the OAuthToken and OAuthTokenSecret
'  properties, and also make sure to clear OAuthVerifier property:
http.oauthToken = oauthToken
http.oauthTokenSecret = oauthTokenSecret
http.OAuthVerifier = ""

'  Now that the http object has valid property values
'  for OAuthConsumerKey, OAuthConsumerSecret,
'   OAuthToken, and OAuthTokenSecret, it can send authenticated
'  Twitter requests to the user's Twitter account.

Else Text1.Text = Text1.Text & http.LastErrorText & vbCrLf End If

gives me the following ChilkatLog: PostUrlEncoded: DllDate: Dec 12 2012 UnlockPrefix: Anything for 30-day trial Username: TIMC-VISTA:timc Architecture: Little Endian; 32-bit Language: ActiveX VerboseLogging: 0 url: RequestData: HttpVersion: 1.1 Verb: GET Path: / Charset: windows-1252 SendCharset: 0 MimeHeader: --RequestData hcCurDate: Thu, 06 Jun 2013 13:12:29 -0400 hcExpire: 11/2012 httpConnect: hostname: port: 443 ssl: 1 Need to establish connection to the HTTP server... ConnectTimeoutMs_1: 10000 calling ConnectSocket2 IPV6 enabled connect with NO heartbeat. connectingTo: resolveHostname1: dnsCacheLookup: Resolving domain name (IPV4) --resolveHostname1 GetHostByNameHB_ipv4: Elapsed time: 16 millisec myIP_1: myPort_1: 7152 connect successful (1) clientHelloMajorMinorVersion: 3.1 buildClientHello: majorVersion: 3 minorVersion: 1 numRandomBytes: 32 sessionIdSize: 0 numCipherSuites: 10 numCompressionMethods: 1 --buildClientHello readIncomingTls_serverHello: processTlsRecord: processHandshake: handshakeMessageType: ServerHello handshakeMessageLen: 0x46 processHandshakeMessage: MessageType: ServerHello Processing ServerHello... ServerHello: MajorVersion: 3 MinorVersion: 1 SessionIdLen: 32 CipherSuite: RSA_WITH_RC4_128_SHA CipherSuite: 00,05 CompressionMethod: 0 Queueing ServerHello message. ServerHello is OK. --ServerHello --processHandshakeMessage --processHandshake --processTlsRecord --readIncomingTls_serverHello HandshakeQueue: MessageType: ServerHello --HandshakeQueue Dequeued ServerHello message. readIncomingTls_6: processTlsRecord: processHandshake: handshakeMessageType: Certificate handshakeMessageLen: 0xb86 processHandshakeMessage: MessageType: Certificate ProcessCertificates: Certificate: derSize: 1357 certSubjectCN: certSerial: 4E60EB8454540F0FECC1CE5A63FAED20 certIssuerCN: VeriSign Class 3 Secure Server CA - G2 --Certificate Certificate: derSize: 1584 certSubjectCN: VeriSign Class 3 Secure Server CA - G2 certSerial: 6E4FFAB3C5E669C4D167C992ABE858C4 certIssuerCN: --Certificate NumCertificates: 2 Queueing Certificates message... --ProcessCertificates --processHandshakeMessage --processHandshake --processTlsRecord --readIncomingTls_6 Dequeued Certificate message. readIncomingTls_6: processTlsRecord: processHandshake: handshakeMessageType: ServerHelloDone handshakeMessageLen: 0x0 processHandshakeMessage: MessageType: ServerHelloDone Queueing HelloDone message. --processHandshakeMessage --processHandshake --processTlsRecord --readIncomingTls_6 DequeuedMessageType: ServerHelloDone OK to ServerHelloDone! No client certificate required by the server. Encrypted pre-master secret with server certificate RSA public key is OK. Sending ClientKeyExchange... Sent ClientKeyExchange message. Sending ChangeCipherSpec... Sent ChangeCipherSpec message. Derived keys. Installed new outgoing security params. Sending FINISHED message.. algorithm: arc4 keyLength: 128 Sent FINISHED message.. readIncomingTls_changeCipherSpec2: processTlsRecord: processChangeCipherSpec: ccsProtocolType: 1 --processChangeCipherSpec --processTlsRecord --readIncomingTls_changeCipherSpec2 readIncomingTls_handshakeFinished2: processTlsRecord: processHandshake: handshakeMessageType: HandshakeFinished handshakeMessageLen: 0xc processHandshakeMessage: MessageType: HandshakeFinished FinishedMsgLen: 12 Queueing Finished message. --processHandshakeMessage --processHandshake --processTlsRecord --readIncomingTls_handshakeFinished2 Dequeue the FINISHED message... Dequeued Finished message. Handshake completed successfully. Secure Channel Established. Connected --httpConnect connectTime1: Elapsed time: 234 millisec sendRequestGetResponse_1: sendRequest: Adding Host header... host: port: 443 Not auto-adding cookies. AddOAuth1Header_2: oauth_timestamp: 1370538749 oauth_nonce: XXXXXX= oauth_consumer_key: XXXXX oauth_verifier: XXXXXX oauth_callback: oob oauth_signature_method: HMAC-SHA1 fullUrl: --AddOAuth1Header_2 sortedParams: oauth_hdr: oauth_callback oauth_hdr: oauth_consumer_key oauth_hdr: oauth_nonce oauth_hdr: oauth_signature_method oauth_hdr: oauth_timestamp oauth_hdr: oauth_verifier oauth_hdr: oauth_version --sortedParams baseStringURI: baseStringURI_encoded: normalizedParams: oauth_callback=oob&oauth_consumer_key=E9PBXr5yLydPAAN0Xddxg&oauth_nonce=XXXXXXX%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1370538749&oauth_verifier=XXXXXXX&oauth_version=1.0 normalizedParams_encoded: oauth_callback%3Doob%26oauth_consumer_key%XXXXXXXX%26oauth_nonce%XXXXXXXX%253D%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1370538749%26oauth_verifier%3DXXXXXX%26oauth_version%3D1.0 signatureBaseString: POST& oauth_signature: XXXXXXXXX= --sendRequest --sendRequestGetResponse_1 sendRequestTime: Elapsed time: 0 millisec ---- Reading HTTP Response ---- readResponse2_4: No transfer-encoding header field. sslContentLength: 21 extraLen: 0 readResponseTime: Elapsed time: 250 millisec --readResponse2_4 processResponse_3: responseStatus: 401 --processResponse_3 --PostUrlEncoded Success. --ChilkatLog


I have the same problem. Part 1 of the example code works fine but Part 2 throws a 401 error. Any solution?


It works only when the second step also the token and the token secret is passed:

CkHttp_putOAuth1(http,True); CkHttp_putOAuthVerifier(http,''); CkHttp_putOAuthConsumerKey(http,pwidechar(fxSocial[i].OAuthConsumerKey)); CkHttp_putOAuthConsumerSecret(http,pwidechar(fxSocial[i].OAuthConsumerSecret)); CkHttp_putOAuthToken(http,pwidechar(fxSocial[i].OAuthAccessToken)); CkHttp_putOAuthTokenSecret(http,pwidechar(fxSocial[i].OAuthTokenSecret));