Skip to content

Instantly share code, notes, and snippets.

@M-Igashi
Forked from supersupermomonga/TwitterWebService.gs
Created December 21, 2016 22:25
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save M-Igashi/750ab08718687d11bff6322b8d6f5d90 to your computer and use it in GitHub Desktop.
Save M-Igashi/750ab08718687d11bff6322b8d6f5d90 to your computer and use it in GitHub Desktop.
'use strict';
function getInstance(consumer_key, consumer_secret) {
return new TwitterWebService_(consumer_key, consumer_secret);
}
var TwitterWebService_ = function (consumer_key, consumer_secret) {
this.consumer_key = consumer_key;
this.consumer_secret = consumer_secret;
}
TwitterWebService_.prototype.getService = function() {
return OAuth1.createService('Twitter')
.setAccessTokenUrl('https://api.twitter.com/oauth/access_token')
.setRequestTokenUrl('https://api.twitter.com/oauth/request_token')
.setAuthorizationUrl('https://api.twitter.com/oauth/authorize')
.setConsumerKey(this.consumer_key)
.setConsumerSecret(this.consumer_secret)
.setCallbackFunction('authCallback')
.setPropertyStore(PropertiesService.getUserProperties())
}
TwitterWebService_.prototype.authorize = function() {
var service = this.getService();
if (service.hasAccess()) {
Logger.log('Already authorized');
} else {
var authorizationUrl = service.authorize();
Logger.log('Open the following URL and re-run the script: %s', authorizationUrl);
}
}
TwitterWebService_.prototype.reset = function() {
var service = this.getService();
service.reset();
}
TwitterWebService_.prototype.authCallback = function(request) {
var service = this.getService();
var isAuthorized = service.handleCallback(request);
var mimeType = ContentService.MimeType.TEXT;
if (isAuthorized) {
return ContentService.createTextOutput('Success').setMimeType(mimeType);
} else {
return ContentService.createTextOutput('Denied').setMimeType(mimeType);
}
}
@M-Igashi
Copy link
Author

Forked to update OAuth1 library v14 due to Project key EoS. You can use following Script ID to include the library.
1rgo8rXsxi1DxI_5Xgo_t3irTw1Y5cxl2mGSkbozKsSXf2E_KBBPC3xTF
The sample code written by YoshiyukiHirano is here.

@kazooou
Copy link

kazooou commented Jun 18, 2018

2018年6月からTwitter社がAPIの仕様を変更して、Callback URLの設定を必須にしたのですが、このスクリプトのどこを改造したら良いでしょうか。

@zensai3805
Copy link

zensai3805 commented Jul 3, 2018

恐らくこのスクリプト自体に修正は不要だと思われます。
Callback URLは、"https://script.google.com/macros/d/[GASのスクリプトID]/usercallback” にて設定した所正しく動いています。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment