我有一個應用程序使用Google JS API以oauth登錄用戶,然後從他們的gmail acct等獲取信息。該應用程序在網上工作正常,但有問題與Trigger.io(Android和iOS版本)。腳本通過google js api在trigger.io應用程序
<script src="https://apis.google.com/js/client.js?onload=ginit"></script>
加載,然後ginit
函數調用gapi
客戶通過client.js加載:
if (!!gapi) {
gapi.client.setApiKey(GoogleApp.apiKey);
}
在Android上,gapi
存在,但不知何故gapi.client
不,導致錯誤。
在iOS上,庫加載工作正常,但隨後調用gapi.auth.authorize
(這可能會導致打開新窗口)會導致Webview錯誤:Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed."
我正在使用子瀏覽器和跨域ajax模塊,但當然無法改變Google庫實現調用的方式。我把代碼忽略每this和類似的錯誤,但仍然在auth不起作用:
try {
gapi.auth.authorize({client_id: GoogleApp.clientId, scope: GoogleApp.scopes, response_type: 'token id_token', immediate: false, approval_prompt: 'force'}, gHandleAuthResult);
} catch (e) {
if (e.indexOf('NSURLErrorCancelled') === -1) { // iOS error on cancelled window, ignore
throw e;
}
}
有沒有使用谷歌API從Trigger.io應用更好的辦法?或者使用Google API的Trigger.io應用的示例?
我的下一個問題可能會與確定js的起源,which is already covered in another post,但還沒有答案。感謝您的幫助!