0
Google検索コンソールからスクリプトを使用してシートにデータを抽出しています。 サイドバーを作成して、ユーザーが自分のデータを分析したいウェブサイトを選択しました。アプリケーションスクリプトのWebページで.gsファイルを使用します。
Googleのすべてのサイトリンクを一覧表示できる機能がありますが、この機能をHTMLファイルで実行しようとするとエラーが発生します。 私はwithSuccessHandler(関数)メソッドを使用して、サーバー側の関数が正常に戻る場合にコールバック関数を実行するように設定します。 。私のgetService関数である(私はOAuth2.0.gsファイルを持っている をエラーがlistAccountSitesが私の機能である「service.hasAccessがlistAccountSitesでの関数ではありません」です。ここに私のhtmlファイルの抜粋です:。
<script src="OAuth2.0.gs"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(function() {
var liste = google.script.run.withSuccessHandler(listAccountSites)
.getService();
console.log(liste);
});
function listAccountSites(service){
if (service.hasAccess()) {
var apiURL = "https://www.googleapis.com/webmasters/v3/sites";
var headers = {
"Authorization": "Bearer " + getService().getAccessToken()
};
var options = {
"headers": headers,
"method" : "GET",
"muteHttpExceptions": true
};
var response = UrlFetchApp.fetch(apiURL, options);
var json = JSON.parse(response.getContentText());
Logger.log(json)
console.log('if')
var URLs = []
for (var i in json.siteEntry) {
URLs.push([json.siteEntry[i].siteUrl, json.siteEntry[i].permissionLevel]);
}
/*
newdoc.getRange(1,1).setValue('Sites');
newdoc.getRange(1,3).setValue('URL du site à analyser');
newdoc.getRange(2,1,URLs.length,1).setValues(URLs);
*/
console.log(URLs);
} else {
console.log('else')
var authorizationUrl = service.getAuthorizationUrl();
Logger.log('Open the following URL and re-run the script: %s', authorizationUrl);
Browser.msgBox('Open the following URL and re-run the script: ' + authorizationUrl);
}
return URLs;
}
</script>
。あなたのhtmlのサイドバー上の機能。jQueryのあなたは自分のGSを実行するために)(google.script.run.yourfunctionを使用する必要があり、ここでは役に立たない 。解決策を見つけたあなたはuse'場合、エラーが消えませんif(service.hasAccess) '? – Cooper