Issue in authentication when GAS OAuth1 library is used.

31 views
Skip to first unread message

Darren D'Mello

unread,
May 23, 2022, 12:06:39 AM5/23/22
to Google Apps Script Community
The Oauth1 library for the other non-payload calls work great But, when there is a payload it just says. 

{ "errors": [ { "code": "UNAUTHORIZED_ACCESS", "message": "This request is not properly authenticated" } ], "request": { "params": {} } }

I have altri tried by stringifying and bare payload. Here is the below code.


function run() {
  var service = getService();
  if (service.hasAccess()) {
      var url = 'https://ads-api.twitter.com/11/accounts/18ce54jfg34/audience_estimate';
    var payload = {
        "targeting_criteria": [{
                "targeting_type": "LOCATION",
                "targeting_value": "96683cc9126741d1"
            },
            {
                "targeting_type": "BROAD_KEYWORD",
                "targeting_value": "cats"
            },
            {
                "targeting_type": "SIMILAR_TO_FOLLOWERS_OF_USER",
                "targeting_value": "14230524"
            },
            {
                "targeting_type": "SIMILAR_TO_FOLLOWERS_OF_USER",
                "targeting_value": "90420314"
            }
        ]
    };
    var response = service.fetch(url, {
      method: 'post',
      payload: payload, // also tried with JSON.stringify(payload)
      headers:{
      "Content-Type":"application/json"
      },
      "muteHttpExceptions":true
    });
    var result = JSON.parse(response.getContentText());
    Logger.log (JSON.stringify(result, null, 2));
  } else {
    var authorizationUrl = service.authorize();
    Logger.log (authorizationUrl);
  }

Reply all
Reply to author
Forward
0 new messages