3

We have the following scenario:

  • User logs into Google Drive with Account A
  • Then, user adds a new account and logs into Google Drive with Account B (two active valid accounts at this point)
  • While in Account B, the user clicks the Create button in Drive. Our app requests the user to select which account he wants to use for the file creation and the user selects Account B (same one he was already using). Our app shows the file picker but the files he gets to see are the ones in the Account A, not in Account B.

We have followed all the steps indicated in the developers API guide, including setting the authorization token. Here is our createPicker function:

function createPicker() {
  if (pickerApiLoaded && oauthToken) {
    new google.picker.PickerBuilder()
      .addView(google.picker.ViewId.DOCS)
      .setSelectableMimeTypes(selectableMimes)
      **.setOAuthToken(oauthToken)**
      .setCallback(pickerCallback)
      .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
      .build()
      .setVisible(true);
  }
}

and this is how we are obtaining the oauthToken value:

gapi.auth.authorize({
          client_id: clientId,
          scope: scope,
          immediate: false,
        }, function(authResult) {
          if (authResult && !authResult.error) {
            **oauthToken = gapi.auth.getToken().access_token;**
            createPicker();
          }
        }); 

While debugging, we have confirmed that, if the user selects Account A, we get one oAuthToken, and if the user selects Account B, we get a different one. So we are sending different tokens for each account, as it is supposed to be.

Any idea on why the user, after selecting Account B (which generates a token for Account B) gets to see the files on Account A? Any idea of what are we missing or doing wrong?

4

1 回答 1

0

默认情况下,选择器将显示在该浏览器中访问过的任何公共文件。这是一种奇怪的行为,很难让选择器完全按照你的意愿去做。

尝试使用功能 Feature.MINE_ONLY

  .enableFeature(google.picker.Feature.MINE_ONLY)

https://developers.google.com/picker/docs/reference#Feature

这将“在显示 Google Drive 中的项目时仅显示用户拥有的文档”。

于 2016-02-04T05:57:28.140 回答