在Google授权后,我试图发布一个没有任何确认的时刻:
GTMOAuth2Authentication *auth;
auth = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:TMH_SOCIAL_GOOGLE_KEYCHAIN
clientID:TMH_SOCIAL_GOOGLE_CLIENTID
clientSecret:TMH_SOCIAL_GOOGLE_SECRET];
if ([auth canAuthorize]) {
NSString *postString = @"{"type":"http:\/\/schemas.google.com\/AddActivity","target":{"id":"tmhabc","type":"http:\/\/schemas.google.com\/AddActivity","description":"First post description","name":"First post"}}";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.googleapis.com/plus/v1/people/me/moments/vault?access_token=%@&key=%@", auth.refreshToken, TMH_SOCIAL_GOOGLE_APIKEY]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
GTMHTTPFetcher *myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];
[myFetcher setAuthorizer:auth];
[myFetcher setPostData:[postString dataUsingEncoding:NSUTF8StringEncoding]];
[myFetcher beginFetchWithCompletionHandler:^(NSData *retrievedData, NSError *error) {
if (error == nil) {
NSLog(@"OK %@", [[NSString alloc] initWithData:retrievedData encoding:NSUTF8StringEncoding]);
} else {
NSLog(@"%@", error.localizedDescription);
}
}];
}
但是收到一个错误401:操作无法完成。(com.google。HTTPStatus错误401.)
我试试这个:
- 在api控制台中授予Google Plus权限
- 授权范围为https://www.googleapis.com/auth/plus.login
- 在网上发现只有这个答案:http://gusclass.com/blog/2013/02/27/common-issues-for-the-new-google-platform-release/家伙在这篇文章中建议使用"data-requestvisibleactions"(但如何在objective c中做到这一点)
我不知道怎么了。
https://developers.google.com/+/api/latest/moments/insert#try-it暂时不工作
有同样的问题,但在服务器端。在将用户重定向到身份验证页面时,您的oauth请求应该包含request_visible_actions
参数。