【问题标题】:Google Plus can't post a momentGoogle Plus 无法发布片刻
【发布时间】:2013-02-15 21:02:15
【问题描述】:

在 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。)

我试试这个:

  1. 在 APIs 控制台中授予 Google Plus 权限
  2. 使用范围“https://www.googleapis.com/auth/plus.login”进行授权
  3. 在网上只找到了这个答案:http://gusclass.com/blog/2013/02/27/common-issues-for-the-new-google-platform-release/ 这篇文章中的家伙建议使用“data-requestvisibleactions”(但如何在目标 c 中执行此操作)

我不知道怎么了。

更新

https : //developers.google.com/+/api/latest/moments/insert#try-它不适用于瞬间插入。

【问题讨论】:

  • 您升级到几天前发布的最新版 Google+ iOS SDK (1.2.1) 了吗?您的代码似乎是手动设置,而不是使用提供的方法。
  • BrettJ,是的,我尝试使用 Google+ SDK developers.google.com/+/mobile/ios/share,但每次我想分享时它都会打开确认对话框。这不方便使用。
  • @RuslTG 你是如何在 iOS 中添加“request_visible_actions”参数的??

标签: objective-c google-api oauth-2.0 google-plus google-oauth


【解决方案1】:

遇到了同样的问题,但在服务器端。在将用户重定向到身份验证页面时,您的 oauth 请求应包含 request_visible_actions 参数。查看我的 questiondiff 的 php 客户端。

【讨论】:

  • "request_visible_actions" 有效!但是……那一刻并没有出现在直播中。
  • 很奇怪,wheresgus.com/appactivitiesdemo 也没有发帖。
  • 如何查看是否已发布?
  • 我收到 200 OK 响应。然后转到我的 Google+ 帐户,什么也没看到。
  • 查看个人资料 -> 关于,检查页面底部的应用程序。会有你的应用程序,当你点击它时,你会得到它的活动。别问为什么藏得这么深。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-19
  • 2017-08-02
  • 2014-04-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多