How to set a custom header in Google Cloud Endpoints Javascript Client?

為{幸葍}努か 提交于 2019-12-04 23:04:16

You can now do this using gapi.client.request, for example:

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);
});

See also the Getting Started page of the Google API Javascript Client documentation.

Try using the header normally, but fetching the token and adding a variable containing it where you need the token to show.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!