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

Kor*_*eel 16 javascript google-api google-cloud-endpoints

我可以使用Javascript客户端从Google Cloud Endpoints获取博客帖子列表:

gapi.client.blog.posts.list().execute(function (resp) {
  console.log(resp);
});
Run Code Online (Sandbox Code Playgroud)

但我需要在Google Cloud Endpoints请求中设置包含用户令牌的自定义标头值(这可能是来自Facebook的访问令牌).如何使用Google的Javascript客户端执行此操作?我可以通过不使用谷歌的Javascript客户端解决这个问题,但我宁愿使用它.

https://developers.google.com/appengine/docs/java/endpoints/consume_js https://developers.google.com/api-client-library/javascript/reference/referencedocs

编辑

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

gapi.auth.setToken({
    access_token: 'this is my custom value'
});
Run Code Online (Sandbox Code Playgroud)

虽然看起来不是很好的做法.有一个更好的方法吗?

Tra*_*vis 0

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