【问题标题】:YouTube api v3 Invalid Credentials access tokenYouTube api v3 无效凭据访问令牌
【发布时间】:2016-06-22 14:13:19
【问题描述】:

尝试在 OAuth 2.0 中使用 Youtube API 时出现 401 Invalid Credentials 错误。

我使用 google 登录 sdk 并通过参数获取 access_token:

    GIDSignIn *sharedSignIn = [GIDSignIn sharedInstance];

sharedSignIn.shouldFetchBasicProfile = NO;

sharedSignIn.scopes = [NSArray arrayWithObjects:
                       @"https://www.googleapis.com/auth/youtube.force-ssl",
                       @"https://www.googleapis.com/auth/youtube",
                       @"https://www.googleapis.com/auth/youtube.readonly",
                      // @"https://www.googleapis.com/auth/youtube.upload",
                       nil];

[sharedSignIn signIn];

比我使用 AFNetworking 库进行 GET 请求

- (void) getInformationWithParams: (NSDictionary *) params
                       method: (NSString *) method
                    onSuccess: (void(^)(NSDictionary *responseObject)) success
                    onFailure: (void (^) (NSError *error)) failure {

[self.requestOperationManager GET:method
                       parameters:params
                         progress:nil
                          success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {

                              NSLog(@"%@", responseObject);

                              if (success) {
                                  success(responseObject);
                              }

                          }
                          failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                              NSLog(@"getInformationWithParams Error: %@", error);

                              if (failure) {
                                  failure(error);
                              }

                          }];

}

之前我做过baseURL init

        NSURL *baseURL = [NSURL URLWithString:@"https://www.googleapis.com/youtube/v3"];
    self.requestOperationManager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL];

最后我得到了请求

    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                     @"snippet",   @"part",
                     @"true",   @"home",
                      myApiKey, @"key",
                        myAccessToken, @"access_token",
                        nil];

[[SMServerManager sharedManager] getInformationWithParams:params
                                                   method:@"activities"
                                                onSuccess:^(NSDictionary *responseObject) {

                                                }
                                                onFailure:^(NSError *error) {

                                                }];

我不明白我做错了什么。

PS:如果不需要使用 access_token,请求就可以工作。

【问题讨论】:

    标签: ios objective-c youtube-api afnetworking google-signin


    【解决方案1】:

    这是一个非常愚蠢的错误。我对几个谷歌帐户感到困惑,并为项目制作了错误的文件。

    【讨论】:

      猜你喜欢
      • 2013-05-03
      • 2014-04-18
      • 1970-01-01
      • 2014-08-13
      • 2019-07-08
      • 2017-08-11
      • 2014-11-13
      • 1970-01-01
      • 2020-09-11
      相关资源
      最近更新 更多