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。)
私はこれを試してみます:
- ApisコンソールでGooglePlusの権限を付与する
- スコープ「https://www.googleapis.com/auth/plus.login」で認証します
- ウェブではこの答えだけが見つかりました:http://gusclass.com/blog/2013/02/27/common-issues-for-the-new-google-platform-release/この投稿の男は「データ- requestvisibleactions」(ただし、Objective cでこれを行う方法)
何が悪いのかわかりません。
アップデート
https://developers.google.com/+/api/latest/moments/insert#try-モーメント挿入では機能しません。