Obtain a bearer token
The value calculated in step 1 must be exchanged for a bearer token by issuing a request to POST oauth2/token:
POST /oauth2/token HTTP/1.1
Host: api.twitter.com
User-Agent: My Twitter App v1.0.23
Authorization: Basic eHZ6MWV2RlM0d0VFUFRHRUZQSEJvZzpMOHFxOVBaeVJn
NmllS0dFS2hab2xHQzB2SldMdzhpRUo4OERSZHlPZw==
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Content-Length: 29
Accept-Encoding: gzip
grant_type=client_credentials
I have most of that done, it's just the "body of the request" I don't know how to do
The value calculated in step 1 must be exchanged for a bearer token by issuing a request to POST oauth2/token:
- The request must be a HTTP POST request.
- The request must include an Authorization header with the value of Basic <base64 encoded value from step 1>.
- The request must include a Content-Type header with the value of application/x-www-form-urlencoded;charset=UTF-8.
- The body of the request must be grant_type=client_credentials.
POST /oauth2/token HTTP/1.1
Host: api.twitter.com
User-Agent: My Twitter App v1.0.23
Authorization: Basic eHZ6MWV2RlM0d0VFUFRHRUZQSEJvZzpMOHFxOVBaeVJn
NmllS0dFS2hab2xHQzB2SldMdzhpRUo4OERSZHlPZw==
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Content-Length: 29
Accept-Encoding: gzip
grant_type=client_credentials
I have most of that done, it's just the "body of the request" I don't know how to do
B4X:
Sub EncodeTwitterConsumerKeyAndSecret(Key As String, Secret As String)
Dim STRutils As StringUtils , BYTutils As ByteConverter ,tempstr As String
tempstr = STRutils.EncodeUrl(Key, "UTF8") & ":" & STRutils.EncodeUrl(Secret, "UTF8")
TwitterEncodedKey = STRutils.EncodeBase64( BYTutils.StringToBytes(tempstr, "UTF8"))
End Sub
'What I have so far:
HttpUtils.PostString("Twitter", "https://api.twitter.com/oauth2/token", "Authorization=Basic " & TwitterEncodedKey & "&Content-Type=application/x-www-form-urlencoded;charset=UTF-8")