/ / gapi.drive.realtimeを使用する場合、認証にgapi.auth2を使用する回避策はありますか? -javascript、google-authentication、google-drive-realtime-api

gapi.drive.realtimeを使用している場合、認証にgapi.auth2を使用する回避策はありますか? - javascript、google-authentication、google-drive-realtime-api

gapi.drive.realtimeにバグがあり、auth2(このGithubの問題を参照してください。)バグの簡単な説明です。古いものを使用する場合 gapi.auth.authorize メソッド、によって提供される機能 gapi.drive.realtime うまく動作する:

gapi.auth.authorize({
client_id: "client-id.apps.googleusercontent.com",
scope: "https://www.googleapis.com/auth/drive.file",
immediate: true
}, (response) => {
if(response.error) {
console.log("Error signing in!");
console.log(response);
} else {
gapi.drive.realtime.load("file-id", (r) => console.log(r));
}
});

リアルタイムセッションが作成され、結果のドキュメントオブジェクトがエラーなしでコンソールに記録されます。ただし、このコードが、同等の機能を使用するように変更された場合、 gapi.auth2

gapi.auth2.authorize({
client_id: "client-id.apps.googleusercontent.com",
scope: "https://www.googleapis.com/auth/drive.file",
prompt: "none"
}, (response) => {
if(response.error) {
console.log("Error signing in!");
console.log(response);
} else {
gapi.drive.realtime.load("file-id", (r) => console.log(r));
}
});

ログインは正常に完了しますが、ファイルに接続すると、次のエラーが記録されます。

GET https://drive.google.com/otservice/gs?rctype=js&rcver=0&id=file-id 401 ()
api:452 Drive Realtime API Error: token_refresh_required: The OAuth token must be refreshed.

ネットワークデバッガーを見ると、1回目と2回目の試行の本当の違いは、2回目の試行中に、 gapi.drive.realtime 送信しません access_token おそらく、ヘッダーで探しているためです gapi.auth そうではない gapi.auth2。これがバグです。で認証 gapi.auth2.init また、同じ動作を表示します。

私が知りたいのは、このバグの既知の修正があるかどうかです。作成に使用できるコードはありますか gapi.drive.realtime の機能を使用する gapi.auth2、または私はただ使用する必要があります gapi.auth

回答:

回答№1は1

このサンプルを使用してみてください githubgoogleサンプル トークンの更新を実装する方法については、これが発生している問題のようです。

dmp.auth.conditionalRefreshAuth = function() {
// We refresh the access token about 10 minutes before it expires.
if (new Date().getTime() + 600000 > dmp.auth.accessTokenExpieryTimestamp) {
dmp.auth.autoRefreshAuth();
}
};