带有AccessToken的Google Picker无法正常工作 [英] Google Picker with AccessToken not working

查看:100
本文介绍了带有AccessToken的Google Picker无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让Google Picker正常工作.我已经使用 PHP League Oauth提供商

I can't seem to get Google Picker working. I have authenticated my user using the PHP League Oauth Provider

经过身份验证后,我的用户的accessToken看起来像这样;

After authenticating, an accessToken for my user looks something like this;

ya67.Fi_dfioriogneegroig7Czdy54z0sdfdvnfr9fn38n3n93

ya67.Fi_dfioriogneegroig7Czdy54z0sdfdvnfr9fn38n3n93

这是我用于呈现选择器的Javascript和HTML代码;

This is my Javascript and HTML code for rendering the picker;

<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}} 获得.

My accessToken is available at {{ token|escape }}.

当我尝试单击添加新文档"按钮时,出现以下错误.

When I try and click the "Add a new document" button, I get the following error.

未捕获的ReferenceError:未在createPicker上定义Google

Uncaught ReferenceError: google is not defined at createPicker

我不知道为什么会这样.我没有正确使用访问令牌吗?

I don't know why this is. Am I not using the access token correctly?

顺便说一句,我需要使用服务器端技术来处理accessToken业务,因为我有多个子域,并且您不能在Google Dev Console中对它们进行通配.因此,我不能仅使用标准示例像这样的来通过客户端进行身份验证

By the way, I need to take of the accessToken business using server side technology because I have multiple sub-domains and you can't wildcard them in Google Dev Console. Therefore, I can't just use a standard example like this one to authenticate via client side.

PS-显然,这些不是我上面代码块中的真实令牌/秘密.它们已更改.

PS - Obviously those aren't my real tokens/secrets in the code block above. They have been changed.

推荐答案

您可能要检查 Google Loader开发者的指南以获取有关如何加载Google API的更多详细信息.

You may want to check Google Loader Developer's Guide for a more detailed information on how to load Google APIs.

如所讨论的,

要加载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>

接下来,使用google.load(模块,版本)在其中加载Google API,

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

  • module 调用您希望在页面上使用的特定API模块.
  • 版本是您要加载的模块的版本号.
  • 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.

调用 google.load 后,您可以使用网页中所有已加载的模块.

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

最后,您可能要检查可用的API ,特别是《 Picker API开发人员指南》 ,并确保您在创建 Picker时没有错过重要功能.对象.

Lastly, you may want to check Available APIs, specifically Picker API Developer's Guide and make sure that you haven't missed important functions when creating a Picker object.

希望有帮助!

这篇关于带有AccessToken的Google Picker无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆