0

我想posts从他/她的google+个人资料中提取用户。

我在https://console.developers.google.com/创建了一个项目

并得到了一个Project ID: xyz Project Number: 58xxxxxxxx17

现在我怎样才能建立一个用户可以sign-in使用的系统,google+我会得到his/her帖子。

我已阅读api文档。但是任何人都可以展示我可以实现我想要的任何示例代码或链接吗?

更新

无法获取用户的活动!!

//apid = my client_id
//user_id = id of user
       $.ajax({
            type: "GET",
            url: "https://www.googleapis.com/plus/v1/people/"+userid+"/activities/public?key="+apid
        })
        .done(function( data ){
            console.log(data);
        });     

控制台收到此错误

         GET 
https://www.googleapis.com/plus/v1/people/106585xxxxxx000/activities/…y=5871xx312xxxxxxxxxxxxxxxxxxxxxxx.com 
    400 (Bad Request)jquery-2.0.3.min.js:6 

    x.ajaxTransport.x.support.cors.e.crossDomain.sendjquery-2.0.3.min.js:6 
    x.extend.ajaxhome.php:788 signinCallbackcb=gapi.loaded_0:355 

    _.k.iucb=gapi.loaded_0:493 ixcb=gapi.loaded_0:499 (anonymous function)cb=gapi.loaded_0:44 h.pu._.C.h.vEcb=gapi.loaded_0:47 

    Wqcb=gapi.loaded_0:47 _.C.yecb=gapi.loaded_0:42 Ap
4

1 回答 1

1

下面是使用登录的 GOOGLE PLUS ID 获取用户公开帖子的代码

请注意: 您应该有客户端 ID,可以按照 Link1Link2中的步骤生成

代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Google+ Sign-in button demo: rendering with JavaScript</title>

<script src="https://apis.google.com/js/client:platform.js" 
type="text/javascript"> </script>

<script type="text/javascript">
var loginFinished = function(authResult)
{  
var token = authResult.access_token; 
gapi.client.load('plus', 'v1', function()
{                           
 //To get the public posts of his/her using their GOOGLEPLUSID               
 window.open("https://www.googleapis.com/plus/v1/people/GOOGLEPLUSID/activities/public?alt=json&access_token="+token+"&maxResults=100");

//if you dont know the GOOGLEPLUSID of his/her you can get GOOGLEPLUSID by calling below API with their details(query) in the result 'id' field gives GOOGLEPLUSID

window.open("https://www.googleapis.com/plus/v1/people?query=Robert Smith+Alamosa&alt=json&maxResults=20&access_token="+token); 

 });  

//OR to see the Public Posts result in console

var request =   gapi.client.request({'path':'/plus/v1/people/GOOGLEPLUSID/activities/public'});
 request.execute(function(resp) {                                       
         console.log(resp);                                                
 });

 };

var options = {
'callback': loginFinished,
'approvalprompt': 'force',
'clientid': 'ENTER YOUR CLIENT ID HERE',
'scope': 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me',
'requestvisibleactions': 'http://schemas.google.com/CommentActivity http://schemas.google.com/ReviewActivity',
'cookiepolicy': 'single_host_origin'
};

var renderBtn = function()
{
 gapi.signin.render('renderMe', options);
}
</script>
</head>

<body onload ="renderBtn()">
<div id="renderMe"></div>  
</body>
</html>

希望能帮助到你。

于 2015-02-04T15:09:35.790 回答