谷歌授权请求问题

时间:2013-06-19 14:35:24

标签: javascript jquery

$.ajax({
    beforeSend: function (request)
    {
        request.setRequestHeader('Authorization', 'Bearer '+ TOKEN);
        //request.setRequestHeader('Authorization', TOKEN);
        //request.setRequestHeader('X-JavaScript-User-Agent', 'Google APIs Explorer');
    },
    url: 'https://www.googleapis.com/plus/v1/people/me/people/visible?key='+ API_KEY,
    //url: 'https://www.googleapis.com/plus/v1/people/me/people/visible',
    //url: 'https://www.googleapis.com/plus/v1/people/'+ UID +'/people/visible',
    //url: 'https://www.googleapis.com/plus/v1/people/'+ UID +'/people/visible?key='+ API_KEY,
    data: null,
    dataType: 'jsonp',
    success: function(result){
      console.log(result);
    }
});

playground中有200 OK且plus.people.list效果很好但是在我的代码中我得到的是:

Object {domain: "usageLimits", reason: "accessNotConfigured", message: "Access Not Configured"}


更新1: 根据{{​​3}},我需要授权的是access_token所以我删除了所有APP_KEY和 根据@SLaks无法使用JSONP设置请求标头。相反,我在查询字符串上传递了不记名令牌,但没有任何改变,同样的问题。无论如何,谢谢你的帮助。

$.ajax({
    //url: 'https://www.googleapis.com/plus/v1/people/me/people/visible?access_token='+ TOKEN,
    //url: 'https://www.googleapis.com/plus/v1/people/me/people/visible?access_token='+ encodeURIComponent(TOKEN),
    //url: 'https://www.googleapis.com/plus/v1/people/me/people/visible?token_type=Bearer&access_token='+ TOKEN,
    //url: 'https://www.googleapis.com/plus/v1/people/me/people/visible?token_type=Bearer&access_token='+ encodeURIComponent(TOKEN),
    //url: 'https://www.googleapis.com/plus/v1/people/'+ UID +'/people/visible?access_token='+ TOKEN,
    //url: 'https://www.googleapis.com/plus/v1/people/'+ UID +'/people/visible?access_token='+ encodeURIComponent(TOKEN),
    //url: 'https://www.googleapis.com/plus/v1/people/'+ UID +'/people/visible?token_type=Bearer&access_token='+ TOKEN,
    //url: 'https://www.googleapis.com/plus/v1/people/'+ UID +'/people/visible?token_type=Bearer&access_token='+ encodeURIComponent(TOKEN),
    data: null,
    dataType: 'jsonp',
    success: function(resp){console.log(resp);}
});


FIXED! 在谷歌apis控制台问题的几个变化固定后,我感到愚蠢。我所要做的只是打开服务中的Google+ API并将域添加到API Access中的通知端点(不要认为第二个有用,但无论如何它现在正在运行!)。

1 个答案:

答案 0 :(得分:1)

您无法使用JSONP设置请求标头。

相反,您应该在查询字符串上传递持票人令牌:"&access_token=" + encodeURIComponent(token)