I've been trying to authenticate to a 3rd party service using oAuth and I get an "Unexpected error" at the UrlFetchApp.fetch() stage. This prompted me to replace the 3rd party service with Twitter whose example is provided in one of the tutorials and I see the same problem with twitter too.
Here is my code.
function testTwitter() {
var oauth = UrlFetchApp.addOAuthService('twitter');
oauth.setRequestTokenUrl('https://api.twitter.com/oauth/request_token');
oauth.setAuthorizationUrl('https://api.twitter.com/oauth/authorize');
oauth.setAccessTokenUrl('https://api.twitter.com/oauth/access_token');
oauth.setConsumerKey('CONSUMER_KEY');
oauth.setConsumerSecret('CONSUMER_SECRET');
var url = 'https://api.twitter.com/1/statuses/mentions.json';
try{
var options = {
"oAuthServiceName" : "twitter",
"oAuthUseToken" : "always",
"method":"GET"
};
var resp = UrlFetchApp.fetch(url,options);
Logger.log(resp.getContentText());
}catch(ex){
Logger.log(ex);
}
}
When I see the logs, I see the following being thrown at the UrlFetchApp.fetch stage.
Exception: Unexpected error:
Am I missing something ? Is the Callback URL necessary ? If yes, where do I specify it ?