Google Plus can't post a moment

浪子不回头ぞ 提交于 2019-12-21 06:38:28

问题


After Google authorization I try to post a moment without any confirmations:

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);
        }
    }];
}

But receive an error 401: The operation couldn’t be completed. (com.google.HTTPStatus error 401.)

I try this:

  1. Grant permissions for Google Plus in Apis Console
  2. Authorize with the scope "https://www.googleapis.com/auth/plus.login"
  3. In the Web found only this answer: http://gusclass.com/blog/2013/02/27/common-issues-for-the-new-google-platform-release/ guy in this post suggests to use "data-requestvisibleactions" (but how to do this in objective c)

I don't know what is wrong.

Update

https : //developers.google.com/+/api/latest/moments/insert#try-it does not work for moment insert.


回答1:


Got the same problem but on server side. Your oauth request should include request_visible_actions parameter while redirecting user to authentication page. Checkout my question and diff for php client.



来源:https://stackoverflow.com/questions/15156417/google-plus-cant-post-a-moment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!