I am developing a Twitter app with Google spreadsheet, but I am having trouble getting a token in the OAuth authentication section of Twitter.
Isn't there something like the localStorage feature in JavaScript?
Here's the code.
function getToken(){
var account
varoath_url="https://api.twitter.com/oauth/authorize?force_login=true&screen_name="+account;
var access_url="https://api.twitter.com/oauth/access_token";
var request_url = "https://api.twitter.com/oauth/request_token";
varoAuthConfig=UrlFetchApp.addOAuthService("twitter");
vara=oAuthConfig.setAccessTokenUrl(oath_url);
var=oAuthConfig.setRequestTokenUrl(access_url);
varoa=oAuthConfig.setAuthorizationUrl(request_url);
var consumer=oAuthConfig.setConsumerKey(ScriptProperties.getProperty("twitterConsumerKey"));
varsecret=oAuthConfig.setConsumerSecret(ScriptProperties.getProperty("twitterConsumerSecret"));
oAuthConfig.set**
is just a set method, so it does not return a valueBased on this point, I think this is what it looks like.
function test(){
// Twitter OAuth Settings
varoAuthConfig=UrlFetchApp.addOAuthService("twitter");
oAuthConfig.setAccessTokenUrl("https://api.twitter.com/oauth/access_token");
oAuthConfig.setRequestTokenUrl("https://api.twitter.com/oauth/request_token");
oAuthConfig.setAuthorizationUrl("https://api.twitter.com/oauth/authorize");
// ConsumerKey/Secret is retrieved from Script Properties
// ScriptProperties is deprecated, so use PropertiesService
varprops=PropertiesService.getScriptProperties();
oAuthConfig.setConsumerKey(props.getProperty("twitterConsumerKey"));
oAuthConfig.setConsumerSecret(props.getProperty("twitterConsumerSecret"));
var options = {
'oAuthServiceName': Value specified for 'twitter', // addOAuthService
'oAuthUseToken': 'always'
};
var url="https://api.twitter.com/1.1/account/verify_credentials.json";
var response=UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
When registering an app on Twitter, remember to set the CallbackURL to https://script.google.com/macros
(I fell in love here).
© 2024 OneMinuteCode. All rights reserved.