1
votes

I have followed and double checked the steps to get a bearer token from https://dev.twitter.com/oauth/application-only

i keep getting the following error :
Status : 403 Forbidden {"errors":[{"code":99,"message":"Unable to verify your credentials","label":"authenticity_token_error"}]}

I tried passing grant_type=client_credentials in body as well as query parameter.

The URL i am hitting is : https://api.twitter.com/oauth2/token?grant_type=client_credentials

Headers Set : Authorization : Basic [base64encoded(client_key:client_secret)] Content-Type : application/x-www-form-urlencoded;charset=UTF-8

I am using poster as the rest client to make the calls.

Could any one point out where i may be going wrong.

Thanks a lot.

1
seems to work for me using commandline curl; you can verify that you've got the right consumer key and secret with: curl -u <consumer_key>:<consumer_secret> -X POST -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" https://api.twitter.com/oauth2/token?grant_type=client_credentials which should give you an access tokenHans Z.

1 Answers

0
votes

Send "grant_type=client_credentials" as the payload.

var options = {
    "method":"post",
    "headers": { 
      "Authorization":"Basic " + Utilities.base64Encode(param),
      "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"
    },
    "payload" : "grant_type=client_credentials"
  };

  var response = UrlFetchApp.fetch(TOKEN_URL,options);