如何在Google Cloud Endpoints Javascript客户端中设置自定义头?

如何在Google Cloud Endpoints Javascript客户端中设置自定义头?,javascript,google-api,google-cloud-endpoints,Javascript,Google Api,Google Cloud Endpoints,我可以使用Javascript客户端从Google云端点获取博客文章列表: gapi.client.blog.posts.list().execute(function (resp) { console.log(resp); }); 但我需要在Google Cloud Endpoints请求中设置一个自定义头值,其中包含一个用户令牌(这可能是来自Facebook的访问令牌)。我如何使用谷歌的Javascript客户端做到这一点?我可以通过不使用谷歌的Javascript客户端来解决这个问题

我可以使用Javascript客户端从Google云端点获取博客文章列表:

gapi.client.blog.posts.list().execute(function (resp) {
  console.log(resp);
});
但我需要在Google Cloud Endpoints请求中设置一个自定义头值,其中包含一个用户令牌(这可能是来自Facebook的访问令牌)。我如何使用谷歌的Javascript客户端做到这一点?我可以通过不使用谷歌的Javascript客户端来解决这个问题,但我更愿意使用它

编辑

看起来我可以像这样传递自定义标题值:

gapi.auth.setToken({
    access_token: 'this is my custom value'
});

但这似乎不是个好习惯。有更好的方法吗?

尝试正常使用标头,但获取令牌并在需要令牌显示的位置添加包含该令牌的变量。

您现在可以使用,例如:

gapi.client.init({
    'clientId': 'YOUR_WEB_CLIENT_ID.apps.googleusercontent.com',
    'scope': 'your_scope'
}).then(function() {
    return gapi.client.request({
        'path': 'http://path/to/your/endpoints/api',
        'headers': { 'mycustomheader': 'myvalue' }
    })
}).then(function(response) {
    console.log(response.result);
}, function(reason) {
    console.log('Error: ' + reason.result.error.message);
});

另请参见Google API Javascript客户端文档的页面

也有同样的问题,并且抛弃了jQuery的JavaScript客户端(在端点后端可以正常工作)。使用
setToken
是否幸运?是否正常使用标题?这是可行的,但它在令牌之前附加了一个字符串“Bearer”,因此我必须执行
token=os.getenv('HTTP\u AUTHORIZATION').split(“”[1]