0
因此,很容易在HTML中加載JavaScript客戶端庫。我說的這一個:如何將Google API Javascript客戶端庫加載到Chrome應用程序中
https://apis.google.com/js/client.js
你只使用加載它,
<script src="https://apis.google.com/js/client.js?onload=checkAuth">
然後你可以使用它..
function checkAuth() {
gapi.auth.authorize(
{
'client_id': CLIENT_ID,
'scope': SCOPES.join(' '),
'immediate': true
}, handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeDiv = document.getElementById('authorize-div');
if (authResult && !authResult.error) {
// Hide auth UI, then load client library.
authorizeDiv.style.display = 'none';
doSomething();
} else {
// Show auth UI, allowing the user to initiate authorization by
// clicking authorize button.
authorizeDiv.style.display = 'inline';
}
}
現在,我的問題:
我該如何在Chrome應用中執行此操作?如何加載JS客戶端庫,以便我可以在Chrome應用程序中使用它。
如果您正在驗證用戶嘗試使用[Chrome應用:鍍鉻標識API(https://developer.chrome.com/apps/app_identity),按照文檔:「網絡身份驗證協議利用HTTP的功能,但Chrome應用程序在應用程序容器中運行;它們不通過HTTP加載,無法執行重定向或設置Cookie。「以下是[JavaScript API]列表(https://developer.chrome.com/apps/api_index),Chrome爲應用程序提供了許多特殊用途的API,如'chrome.runtime'和'chrome.alarms'。希望這可以幫助! –