Google api 如何使用分页显示来自Google的圆圈+;
我已经将maxResults设置为10,我想知道如何在nextpageToken中使用查看更多圆圈,通过单击查看更多按钮,接下来的10个圆圈必须显示,并一直显示到Google+中的最后一个圆圈。请帮我解决这个问题。 请参阅下面我的代码:Google api 如何使用分页显示来自Google的圆圈+;,google-api,google-plus,Google Api,Google Plus,我已经将maxResults设置为10,我想知道如何在nextpageToken中使用查看更多圆圈,通过单击查看更多按钮,接下来的10个圆圈必须显示,并一直显示到Google+中的最后一个圆圈。请帮我解决这个问题。 请参阅下面我的代码: <html> <head> <title>Google+ JavaScript Quickstart</title> <script type="text/javascript"> (fu
<html>
<head>
<title>Google+ JavaScript Quickstart</title>
<script type="text/javascript">
(function() {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
<!-- JavaScript specific to this application that is not related to API
calls -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" ></script>
</head>
<body>
<div id="gConnect">
<button class="g-signin"
data-scope="https://www.googleapis.com/auth/plus.login"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-clientId="my client id"
data-callback="onSignInCallback"
data-theme="dark"
data-cookiepolicy="single_host_origin">
</button>
</div>
<div id="authOps" style="display:none">
<h2>User is now signed in to the app using Google+</h2>
<p>If the user chooses to disconnect, the app must delete all stored
information retrieved from Google for the given user.</p>
<button id="disconnect" >Disconnect your Google account from this app</button>
<h2>User's profile information</h2>
<div id="profile"></div>
<h2>User's friends that are visible to this app</h2>
<div id="visiblePeople"></div>
<p><a href="#" id="getMore" onClick="getMore()">View More</a></p>
<h2>Authentication Logs</h2>
<pre id="authResult"></pre>
</div>
</body>
<script type="text/javascript">
var helper = (function() {
var BASE_API_PATH = 'plus/v1/';
return {
/**
* Hides the sign in button and starts the post-authorization operations.
*
* @param {Object} authResult An Object which contains the access token and
* other authentication information.
*/
onSignInCallback: function(authResult) {
gapi.client.load('plus','v1', function(){
$('#authResult').html('Auth Result:<br/>');
for (var field in authResult) {
$('#authResult').append(' ' + field + ': ' +
authResult[field] + '<br/>');
}
if (authResult['access_token']) {
$('#authOps').show('slow');
$('#gConnect').hide();
helper.profile();
helper.people();
} else if (authResult['error']) {
// There was an error, which means the user is not signed in.
// As an example, you can handle by writing to the console:
console.log('There was an error: ' + authResult['error']);
$('#authResult').append('Logged out');
$('#authOps').hide('slow');
$('#gConnect').show();
}
console.log('authResult', authResult);
});
},
/**
* Calls the OAuth2 endpoint to disconnect the app for the user.
*/
disconnect: function() {
// Revoke the access token.
$.ajax({
type: 'GET',
url: 'https://accounts.google.com/o/oauth2/revoke?token=' +
gapi.auth.getToken().access_token,
async: false,
contentType: 'application/json',
dataType: 'jsonp',
success: function(result) {
console.log('revoke response: ' + result);
$('#authOps').hide();
$('#profile').empty();
$('#visiblePeople').empty();
$('#authResult').empty();
$('#gConnect').show();
},
error: function(e) {
console.log(e);
}
});
},
/**
* Gets and renders the list of people visible to this app.
*/
people: function() {
var request = gapi.client.plus.people.list({
'userId': 'me',
'collection': 'visible',
'selfLink':'http://localhost/Google+/trail+.html',
'maxResults':10,`enter code here`
'items[]' : 'list',
'nextPageToken': 'CAIQ0K3cq5DEtAIgAygB'
});
request.execute(function(people) {
$('#visiblePeople').empty();
$('#visiblePeople').append('Number of people visible to this app: ' +
people.totalItems + '<br/>');
for (var personIndex in people.items) {
person = people.items[personIndex];
$('#visiblePeople').append('<img src="' + person.image.url + '">');
$('#visiblePeople').append(''+ person.displayName + '</br>'+ '</br>');
}
});
},
/**
* Gets and renders the currently signed in user's profile data.
*/
profile: function(){
var request = gapi.client.plus.people.get( {'userId' : 'me'} );
request.execute( function(profile) {
$('#profile').empty();
if (profile.error) {
$('#profile').append(profile.error);
return;
}
$('#profile').append(
$('<p><img src=\"' + profile.image.url + '\"></p>'));
$('#profile').append(
$('<p>Hello ' + profile.displayName + '!<br />Tagline: ' +profile.tagline + '!<br />Email id: ' +profile.email +
+ '<br />About: ' + profile.aboutMe + '</p>'));
if (profile.cover && profile.coverPhoto) {
$('#profile').append(
$('<p><img src=\"' + profile.cover.coverPhoto.url + '\"></p>'));
}
});
}
};
})();
/**
* jQuery initialization
*/
$(document).ready(function() {
$('#disconnect').click(helper.disconnect);
if ($('[data-clientid="YOUR_CLIENT_ID"]').length > 0) {
alert('This sample requires your OAuth credentials (client ID) ' +
'from the Google APIs console:\n' +
' https://code.google.com/apis/console/#:access\n\n' +
'Find and replace YOUR_CLIENT_ID with your client ID.'
);
}
});
/**
* Calls the helper method that handles the authentication flow.
*
* @param {Object} authResult An Object which contains the access token and
* other authentication information.
*/
function onSignInCallback(authResult) {
helper.onSignInCallback(authResult);
}
function getMore()
{
helper.people();
}
</script>
</html>
Google+JavaScript快速启动
(功能(){
var po=document.createElement('script');
po.type='text/javascript';po.async=true;
po.src=https://plus.google.com/js/client:plusone.js';
var s=document.getElementsByTagName('script')[0];
s、 parentNode.insertBefore(po,s);
})();
用户现在已使用Google登录到该应用程序+
如果用户选择断开连接,应用程序必须删除所有存储的
从Google为给定用户检索的信息
断开你的Google帐户与此应用的连接
用户配置文件信息
此应用可见的用户好友
身份验证日志
var helper=(函数(){
var BASE_API_PATH='plus/v1/';
返回{
/**
*隐藏“登录”按钮并启动授权后操作。
*
*@param{Object}authResult包含访问令牌和
*其他身份验证信息。
*/
OnSignncCallback:函数(authResult){
load('plus','v1',function(){
$('#authResult').html('Auth Result:
');
for(authResult中的变量字段){
$('#authResult')。追加(''+字段+':'+
authResult[field]+'
');
}
if(authResult['access_token']){
$('authOps')。show('slow');
$(“#gConnect”).hide();
helper.profile();
helper.people();
}else if(authResult['error']){
//出现错误,这意味着用户未登录。
//例如,您可以通过写入控制台来处理:
log('出现错误:'+authResult['error']);
$('#authResult')。追加('注销');
$('authOps')。隐藏('slow');
$('#gConnect').show();
}
log('authResult',authResult);
});
},
/**
*调用OAuth2端点以断开该用户的应用程序。
*/
断开连接:函数(){
//撤消访问令牌。
$.ajax({
键入:“GET”,
网址:'https://accounts.google.com/o/oauth2/revoke?token=' +
gapi.auth.getToken().access\u令牌,
async:false,
contentType:'应用程序/json',
数据类型:“jsonp”,
成功:功能(结果){
log('撤销响应:'+结果);
$('#authOps').hide();
$('#profile').empty();
$(“#visiblePeople”).empty();
$('#authResult').empty();
$('#gConnect').show();
},
错误:函数(e){
控制台日志(e);
}
});
},
/**
*获取并呈现此应用可见的人员列表。
*/
人员:功能(){
var request=gapi.client.plus.people.list({
'userId':'me',
“集合”:“可见”,
“自链接”:http://localhost/Google+/trail+.html',
“maxResults”:10,`在此处输入代码`
'项目[]':'列表',
“nextPageToken”:“CAIQ0K3cq5DEtAIgAygB”
});
请求.执行(功能(人员){
$(“#visiblePeople”).empty();
$(“#visiblePeople”).append('此应用程序可见的人数:'+
people.totalItems+“
”);
for(person.items中的变量personIndex){
person=people.items[personIndex];
$(“#visiblePeople”).append(“”);
$(“#visiblePeople”).append(“+person.displayName+”“+””);
}
});
},
/**
*获取并呈现当前登录用户的配置文件数据。
*/
配置文件:函数(){
var request=gapi.client.plus.people.get({'userId':'me'});
执行(函数(配置文件){
$('#profile').empty();
if(profile.error){
$('#profile').append(profile.error);
返回;
}
$('#profile')。追加(
美元("p>");;
$('#profile')。追加(
$(“Hello”+profile.displayName+”!
标语:“+profile.Tagline+”!
电子邮件id:“+profile.Email”+
+“
关于:”+profile.aboutMe+”);
if(profile.cover和profile.coverPhoto){
$('#profile')。追加(
美元("p>");;
}
});
}
};
})();
/**
*jQuery初始化
*/
$(文档).ready(函数(){
$(“#断开连接”)。单击(helper.disconnect);
如果($('[data clientid=“YOUR_CLIENT_ID”]')。长度>0){
警报('此示例需要您的OAuth凭据(客户端ID)'+
'从Google API控制台:\n'+
' https://code.google.com/apis/console/#:access\n\n'+
'查找您的客户ID并将其替换为您的客户ID。'
);
}
});
/**
*调用处理身份验证流的帮助器方法。
*
*@param{Object}authResult包含访问令牌和
*其他身份验证信息。
*/
函数onSignncCallback(authResult){
helper.onSigningCallback(authResult);
}
函数getMore()
{
helper.people();
}
看起来这里可能有几个问题。您似乎至少掌握了一些如何使用people.list的要点,但您似乎正在尝试将一些响应字段添加到请求字段中。有关请求参数和预期响应的完整详细信息,请参阅
在第一次调用时,您只需要传递userId
和collection
参数。由于要限制页面大小,还需要传递maxResults
,因此您的调用看起来像
var requestParams = {
'userId': 'me',
'collection': 'visible',
'maxResults': 10
};
gapi.client.plus.people.list( requestParams ).execute(peopleCallback);
下次调用“列出更多”按钮时,您需要包括nextPageToken a
peopleCallback: function(response){
nextPageToken = response.nextPageToken;
items.forEach(function(item){
$('#visiblePeople').append(''+person.displayName+'');
});
}
var requestParams = {
'userId': 'me',
'collection': 'visible',
'maxResults': 10,
'pageToken': nextPageToken
};
gapi.client.plus.people.list( requestParams ).execute(peopleCallback);