oauth 2.0 - 执行融合表时获取"invalid credentials" 从谷歌小工具插入



我们有一个Google Gadget,它通过Fusion Table API与用户的Google帐户连接到Fusion Tables。它执行SELECT和INSERT。

我们使用OAuth1 (opensocial的shinglibrary)构建小工具。对于已弃用的Fusion Table API版本,它工作得很好。当我们将其迁移到新的PAPI时,选择q可以正常工作,因为不需要使用OAuth2进行身份验证。然而,对于INSERT,这是必需的。opensocial的文档还没有完全更新:http://docs.opensocial.org/display/OSREF/OpenSocial+Specification+Considerations

我不知道如何成功地使用OAuth2来执行插入。我们有在域级别读/写的API权限,用户有对Fusion表的所有者权限。

我得到的错误是说"无效凭据"相当模糊,我不知道为什么。

这是我们的小工具标题:

<OAuth>
    <Service name="google">
    <Access url="https://www.google.com/accounts/OAuthGetAccessToken" method="GET" />
    <Request url="https://www.google.com/accounts/OAuthGetRequestToken?scope=https://www.googleapis.com/auth/fusiontables%20https://docs.google.com/feeds/default/private"
         method="GET" />
    <Authorization url="https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=http://oauth.gmodules.com/gadgets/oauthcallback" />
    </Service>
</OAuth>

我不确定如何更新,所以我添加了另一个标题:

<OAuth2>
    <Service name="google">
    <Authorization url="https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=http://oauth.gmodules.com/gadgets/oauth2callback" />
    </Service>
</OAuth2>

调用时,执行以下操作:

options = {};
options[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
options[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
options[gadgets.io.RequestParameters.POST_DATA] = postData;
options[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.OAUTH2;
options[gadgets.io.RequestParameters.HEADERS] = {'Authorization':'{encrypted fusiontable key}'};  //not sure if this helps but its extra
options[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] = "google";
options[gadgets.io.RequestParameters.OAUTH_USE_TOKEN] = "always";
URL = https://www.googleapis.com/fusiontables/v1/query?key={encrypted fusiontable key} &client_id={id number}”;
postData=”sql=INSERT…”;
gadgets.io.makeRequest(URL, handlerWrapper, options);

谢谢!

如果正在执行写请求,则需要提供oauth令牌,该令牌编码用户访问表的权限。它看起来像是在gadget .io. requestparameters . oauth_request_token中。该键用于公共表的读访问。此外,您可能需要将OAUTH_SERVICE_NAME设置为"fusiontables"。

相关内容

最新更新