问题:如何使用带有“me”参数的people.get?
我知道在使用https://www.googleapis.com/plus/v1/people/{id}?key={key}
但是当我使用“我”作为id时,我应该包括哪些参数?
(我在auth中使用response_type=code
编辑:(已修复)
我正在使用ASP.NET,我发现this link,但访问令牌json的POST请求会引发错误。发送请求有效,但是当我使用GetResponse()
时,我收到错误(400)。而且我也不确定我使用的uri是否正确:https://accounts.google.com/o/oauth2/token
编辑2:
问题解决了。请求很糟糕,因为我在写入Stream之前将参数字符串转换为byte []时使用了UTF32Encoding
而不是UTF8Encoding
。 UTF8Encoding
效果很好。 :)
我在这个问题之后写的代码:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
UTF8Encoding utfenc = new UTF8Encoding();
byte[] bytes = utfenc.GetBytes(parameters);
Stream os = null;
try // send the post
{
webRequest.ContentLength = bytes.Length; // Count bytes to send
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length); // Send it
}
// error handling...
try // get the response
{
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse == null)
{ return null; }
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
return sr.ReadToEnd().Trim();
}
// error handling...
他用参数from here调用它,返回的字符串(json)包含我的access_token。
答案 0 :(得分:2)
我们为Google+ API开发了一个.NET客户端库。该库使您可以轻松地使用任何.NET编程语言(如C#,VB.NET或ASP.NET
)中的Google+ API您可以在此处找到有关适用于Google+的.NET库的更多详细信息:http://www.googleplustips.com/resources/3332-NET-Library-Google-APIs-released.aspx
当前版本支持所有Google+ API版本1,并与API Key配合使用。调用任何Google API只需要一次方法调用。
答案 1 :(得分:1)
只要您使用(OAuth)身份验证用户的访问令牌访问应用,就可以使用me
ID。引用G+ API documentation:
如果使用userId值“me”,则此方法需要使用已授予OAuth范围https://www.googleapis.com/auth/plus.me的令牌进行身份验证。详细了解using OAuth。
示例:在使用PHP API客户端时,在发出例如
$plus_api = new apiPlusService($client); // $client is the apiClient() object
$plus_api->activities->listActivities('me', ...);
您必须先执行以下命令设置经过身份验证的用户的访问令牌:
$client->setAccessToken($access_token);
使用该设置,可以毫无问题地识别me
ID。
答案 2 :(得分:1)
我发送了一个POST请求(info here)以获取Oauth2 access_token并使用:
https://www.googleapis.com/plus/v1/people/me?key={key}&access_token={token}
答案 3 :(得分:1)
GetActivity和ListComments获取所有数据,或者它有一些方法(使用nextPageToken)来获取所有项目?
每个方法调用都会逐页返回结果集。返回的对象有一个名为NextPageToken的属性,可以在下次调用时传递,以检索结果集的下一页。