質問編集履歴
1
あ
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,36 +16,98 @@
|
|
16
16
|
|
17
17
|
```ここに言語を入力
|
18
18
|
|
19
|
-
function getTrends() {
|
20
19
|
|
21
|
-
let service = getService();
|
22
20
|
|
23
|
-
|
21
|
+
function getOAuthURL() {
|
24
22
|
|
25
|
-
|
23
|
+
Logger.log(getService().authorize());
|
26
24
|
|
27
|
-
|
25
|
+
}
|
28
26
|
|
29
|
-
|
27
|
+
|
30
28
|
|
31
|
-
|
29
|
+
// サービス取得
|
32
30
|
|
33
|
-
|
31
|
+
function getService() {
|
34
32
|
|
35
|
-
|
33
|
+
return OAuth1.createService('Twitter')
|
36
34
|
|
37
|
-
|
35
|
+
.setAccessTokenUrl('https://api.twitter.com/oauth/access_token')
|
38
36
|
|
37
|
+
.setRequestTokenUrl('https://api.twitter.com/oauth/request_token')
|
38
|
+
|
39
|
+
.setAuthorizationUrl('https://api.twitter.com/oauth/authorize')
|
40
|
+
|
41
|
+
// 設定した認証情報をセット
|
42
|
+
|
43
|
+
.setConsumerKey(PropertiesService.getScriptProperties().getProperty("CONSUMER_API_KEY"))
|
44
|
+
|
45
|
+
.setConsumerSecret(PropertiesService.getScriptProperties().getProperty("CONSUMER_API_SECRET"))
|
46
|
+
|
47
|
+
.setCallbackFunction('authCallback')
|
48
|
+
|
49
|
+
// 認証情報をロパティストアにセット(これにより認証解除するまで再認証が不要になる)
|
50
|
+
|
51
|
+
.setPropertyStore(PropertiesService.getUserProperties());
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
// 認証成功時に呼び出される処理を定義
|
60
|
+
|
61
|
+
function authCallback(request) {
|
62
|
+
|
63
|
+
var service = getService();
|
64
|
+
|
65
|
+
var authorized = service.handleCallback(request);
|
66
|
+
|
67
|
+
if (authorized) {
|
68
|
+
|
69
|
+
return HtmlService.createHtmlOutput('success!!');
|
70
|
+
|
71
|
+
} else {
|
72
|
+
|
73
|
+
return HtmlService.createHtmlOutput('failed');
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
// function getTrends() {
|
80
|
+
|
81
|
+
// let service = getService();
|
82
|
+
|
83
|
+
// if (service.hasAccess()) {
|
84
|
+
|
85
|
+
// // id=1118370 を指定することで、東京のトレンドを取得
|
86
|
+
|
87
|
+
// let url = 'https://api.twitter.com/1.1/trends/place.json?id=1118370';
|
88
|
+
|
89
|
+
// let response = service.fetch(url, {
|
90
|
+
|
91
|
+
// method: 'get'
|
92
|
+
|
93
|
+
// });
|
94
|
+
|
95
|
+
// let result = JSON.parse(response.getContentText());
|
96
|
+
|
97
|
+
// let ss = SpreadsheetApp.getActiveSpreadsheet();
|
98
|
+
|
39
|
-
let sheet = ss.getSheetByName("Trend2");
|
99
|
+
// let sheet = ss.getSheetByName("Trend2");
|
40
100
|
|
41
101
|
|
42
102
|
|
43
|
-
let val = sheet.getRange("A1:B50" ).setValue(result);
|
103
|
+
// let val = sheet.getRange("A1:B50" ).setValue(result);
|
44
104
|
|
45
105
|
|
46
106
|
|
47
107
|
|
48
108
|
|
49
|
-
}}
|
109
|
+
// }}
|
110
|
+
|
111
|
+
|
50
112
|
|
51
113
|
```
|