1
我正在研究Google表格< - > Salesforce集成並使用Salesforce編程語言進行開發 - Force.com平臺上的Apex。通過服務帳戶密鑰訪問Google表格API
目前我正在嘗試連接到Google表格API。我使用的是服務帳戶密鑰,因此Salesforce可以從Google表格中提取數據,而不需要每次發出查詢時進行手動授權。
我正在設置服務帳戶密鑰,並且我正在成功發送請求以獲取access_code。
然後我試圖查詢API,使用下面的類:
/****** API CALLOUT *******/
public static HttpResponse googleSheetsCallout(){
//the below line provides a string containing access token to google
string accessCode = getAccessToken();
//I found this endpoint structure online, this may be why my script
//isn't working. However, I am struggling to find the alternative.
string endpoint = 'https://sheets.googleapis.com/v4/spreadsheets/params=[SPREADSHEET ID GOES HERE]/values/[RANGE GOES HERE]?access_token=';
httpRequest req = new httpRequest();
req.setEndpoint(endpoint+accessCode);
req.setMethod('GET');
req.setTimeout(120000);
httpResponse res = new http().send(req);
System.debug ('res is ' +res);
return res;
}
當我運行這個功能是什麼數收益:
|CALLOUT_RESPONSE|[71]|System.HttpResponse[Status=Forbidden, StatusCode=403]
|USER_DEBUG|[72]|DEBUG|res is System.HttpResponse[Status=Forbidden, StatusCode=403]
我啓用了谷歌表的訪問中谷歌開發者控制檯菜單,有趣的是,當在控制檯上大笑時,Google似乎發現API請求被髮送出去(它們出現在活動圖表中)。