0

我似乎無法獲得谷歌選取器工作。我已經驗證使用PHP League Oauth Provider谷歌選擇器使用的accessToken不工作

驗證之後,爲的accessToken我的用戶看起來像這樣我的用戶;

ya67.Fi_dfioriogneegroig7Czdy54z0sdfdvnfr9fn38n3n93

這是我的Javascript和用於呈現picker的HTML代碼;

<a href="{{ appContextInstallId }}/authenticate" class="btn info"> 
    <i class="icon-bolt"></i> Authenticate 
</a> 

<button onClick="createPicker()">Add a new document</button> 

<script type="text/javascript"> 

    var developerKey = 'erteetr43gg-V34y4httytjyjytjyttyjyjyjjy'; 
    var clientId = "373498750987-5dsfwerrwewerweewrl.apps.googleusercontent.com" 
    var appId = "373498750987" 

    var scope = ['https://www.googleapis.com/auth/drive']; 
    var pickerApiLoaded = false; 

    // Use the Google API Loader script to load the google.picker script. 

    // Create and render a Picker object for searching images. 
    function createPicker() { 
     var view = new google.picker.View(google.picker.ViewId.DOCS); 
     var picker = new google.picker.PickerBuilder() 
      .enableFeature(google.picker.Feature.NAV_HIDDEN) 
      .enableFeature(google.picker.Feature.MULTISELECT_ENABLED) 
      .setAppId(appId) 
      .setOAuthToken("{{ token|escape }}") 
      .addView(view) 
      .addView(new google.picker.DocsUploadView()) 
      .setDeveloperKey(developerKey) 
      .setCallback(pickerCallback) 
      .build(); 

     picker.setVisible(true); 
    } 

    // A simple callback implementation. 
    function pickerCallback(data) { 
     // makes an ajax call.... 
    } 
</script> 

<!-- The Google API Loader script. --> 
<script type="text/javascript" src="https://apis.google.com/js/api.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 

我的accessToken可用於{{ token|escape }}

當我試着點擊「添加新文檔」按鈕,我碰到下面的錯誤。

Uncaught ReferenceError: google is not defined at createPicker

我不知道這是爲什麼。我沒有正確使用訪問令牌嗎?

順便說一句,我需要採用服務器端技術accessToken業務,因爲我有多個子域,你不能在谷歌開發控制檯通配符。因此,我不能只用一個標準的例子like this one通過客戶端進行身份驗證。

PS - 顯然,這些都不是我真正的令牌/在上面的代碼塊祕密。他們已經改變了。

回答

0

您可能要檢查Google Loader Developer's Guide關於如何加載谷歌的API的更多詳細信息。

如前所述,

To load the APIs, include the following script in the header of your web page.

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

Next, load the Google API with google.load(module, version), where

  • module calls the specific API module you wish to use on your page.
  • version is the version number of the module you wish to load.

After you call google.load , you can use all of the loaded modules in your web page.

最後,你可能要檢查Available APIs,特別是Picker API Developer's Guide並確保創建Picker對象時,你有沒有錯過重要的功能。

希望有幫助!