Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';我们无法让Google Plus API正常工作_Javascript_Json_Google Plus - Fatal编程技术网

Javascript Can';我们无法让Google Plus API正常工作

Javascript Can';我们无法让Google Plus API正常工作,javascript,json,google-plus,Javascript,Json,Google Plus,我已经试着理解API有一段时间了。但我只是迷路了 我正在尝试做一些简单的事情,比如检索和显示我的Google Plus标语 $.getJSON("https://www.googleapis.com/plus/v1/people/103039534797695934641?key=xxxxxxxxxxxxxxxxxxxxxxxxxxx", function(data) { html = data.nickname; // Insert the generated HTML t

我已经试着理解API有一段时间了。但我只是迷路了

我正在尝试做一些简单的事情,比如检索和显示我的Google Plus标语

$.getJSON("https://www.googleapis.com/plus/v1/people/103039534797695934641?key=xxxxxxxxxxxxxxxxxxxxxxxxxxx", function(data) {

    html = data.nickname;

    // Insert the generated HTML to the DOM
    $('.shots').html(html);

});
我做错了什么? 我应该在链接中插入回调吗?如果是,你知道怎么做吗?
我已经尝试了我所能想到的所有方法。

除非您需要更具体的东西,否则您所需要做的就是将
数据。昵称
更改为
数据。标语

$.getJSON("https://www.googleapis.com/plus/v1/people/103039534797695934641?key=AIzaSyBaDZGM-uXuHc-VZZ2DINzVBcIDMN_54zg", function(data) {
    var html = data.tagline;

    // Insert the generated HTML to the DOM
    $('.shots').html(html);
});
您可以在
$.getJSON
中使用的浏览器(Chrome/Firefox适用于我)中打开,以查看
数据
包含的更多属性,例如
数据.kind
数据.nickname
数据.occulation

您应该尝试使用示例开始,而不是对端点执行XHR,传递API密钥。。。并有效地编写自己的客户机库

此外,如果您只是想看看API可以做什么,那么您应该从开始

以下HTML满足您的需要:

<html>
  <body>
  </body>
  <script>
    var key = 'YOUR_API_KEY';
    function doStuff(){
      gapi.client.load('plus','v1', function(){
        gapi.client.setApiKey(key);
        gapi.client.plus.people.get({'userId': '103039534797695934641'}).execute(function(result){
          alert(result.tagline);
          console.log(JSON.stringify(result));
        });
      });
    }
  </script>
  <script src="https://apis.google.com/js/client.js?onload=doStuff"></script>
</html>

var key='您的API_key';
函数doStuff(){
load('plus','v1',function(){
gapi.client.setApiKey(key);
gapi.client.plus.people.get({'userId':'103039534797695934641')。执行(函数(结果){
警报(结果标记行);
log(JSON.stringify(result));
});
});
}

请注意,我使用的是谷歌提供的客户端库。您可以通过在浏览器中打开控制台并浏览gapi.client.plus[…]方法来探索更多内容。

您确定密钥正确吗。使用Postman或其他rest客户机查看结果,键i是正确的。如果你遵循这个链接:那么你可以看到我应该得到什么。