2017-08-28 23 views
0

我是這個論壇的新手,想知道是否有人能夠幫助我。Google腳本403每週2/7天出錯

我使用Google腳本來追蹤Google公司Instagram帳戶中Google追蹤者的數量。

劇本很好地跑了大約六個星期,但在過去2週期間,在每週連續兩天我得到一個錯誤的電子郵件,上面寫着:

請求失敗https://www.instagram.com/hy.am_studios/?__a=1 返回碼403 。截斷的服務器響應:< html ...(使用 muteHttpExceptions選項來檢查完整響應)。 (第14行,文件 "代碼")

腳本的代碼如下:

// the name of the sheet within your document 
var sheetName = "Marketing // Instagram Follower Tracker"; 
// the name of the Instagram account you want the follower count for 
var instagramAccountName = "hy.am_studios"; 

function insertFollowerCount() { 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheetByName(this.sheetName); 
    sheet.appendRow([Utilities.formatDate(new Date(), "GMT", "dd/MM/yyyy"), getInstagramFollowerCount(this.instagramAccountName)]); 
}; 

function getInstagramFollowerCount(username) { 
    var url = "https://www.instagram.com/" + username + "/?__a=1"; 
    var response = UrlFetchApp.fetch(url).getContentText(); 
    return JSON.parse(response).user.followed_by.count; 
} 

任何人都可以做的這個任何意義?真正讓我惱火的是腳本每週運行五天,但每週兩天都會產生這個錯誤。

在此先感謝您的幫助!

最良好的祝願,

大衛

回答

0

提到這個related SO post。建議的workaround是通過撤銷您Google帳戶的安全設置中的訪問權限給www.google.com以及Apps腳本(電子表格等)的來源。然後將oAuthServiceName參數更改爲其他值並重新運行該腳本。

您還可以檢查此thread

  1. 跑到資源 - 優秀的谷歌服務...
  2. 點擊鏈接,谷歌開發者控制檯
  3. 點擊了該證書節側邊欄
  4. 在公共API訪問下點擊創建新密鑰
  5. 點擊瀏覽器密鑰
  6. 接着加入鍵,它生成的URL字符串

的末尾,以便完整的URL字符串看起來像這樣「鍵=?」:

var url = 'https://www.googleapis.com/admin/directory/v1/groups?key=XXXXXXXXXXX-XXXXXXXXXXXXX-XXXXXXXXXXXXX'; 

希望這有助於!

+0

謝謝,請試試看! –