我正在尝试获取在我的iOS应用中在Google +上共享链接的次数。我正在尝试以下代码
NSString *post = @"[{\"method\":\"pos.plusones.get\",\"id\":\"p\",\"params\":{\"nolog\":true,\"id\":\"http://stylehatch.co/\",\"source\":\"widget\",\"userId\":\"@viewer\",\"groupId\":\"@self\"},\"jsonrpc\":\"2.0\",\"key\":\"p\",\"apiVersion\":\"v1\"}]";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat : @"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"https://clients6.google.com/rpc?key=my_api_key"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *requestResponse;
NSError *err;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&requestResponse error:&err];
return data;
但它返回以下错误
"未配置访问权限。您的API(+1 API)未启用 项目。请使用Google Developers Console更新您的 。构造"
答案 0 :(得分:0)
在Google Developers Console中
https://console.developers.google.com/project/googeplussignin/apiui/apis/library
在那里你可以找到这么多的API。启用所需的API。
答案 1 :(得分:0)
似乎google不再允许将此api用于公共用途。我找到了答案here。
我们现在需要向https://plusone.google.com/_/+1/fastbutton?url=http://www.facebook.com
发送获取请求