首页 \ 问答 \ YouTube API v3无效的凭据访问令牌(YouTube api v3 Invalid Credentials access token)

YouTube API v3无效的凭据访问令牌(YouTube api v3 Invalid Credentials access token)

尝试在OAuth 2.0中使用Youtube API时,我收到401 Invalid Credentials错误。

我使用google登录sdk并使用params获取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:如果他们不需要使用acces_token请求工作。


I am getting 401 Invalid Credentials error trying to use the Youtube API in the OAuth 2.0.

I used google sign in sdk and get access_token with params:

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

Than I used AFNetworking library for GET request

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

                          }];

}

previously I did baseURL init

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

and in the end I get request through

    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) {

                                                }];

I don't understand what I'm doing wrong.

PS: Requests work if they don't need to use acces_token.


原文:https://stackoverflow.com/questions/35870665
更新时间:2019-10-10 02:37

最满意答案

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


It was a very stupid mistake. I'm confused in several google accounts and make wrong files for project.

2016-03-08

相关问答

更多

Youtube api v3显示“Access Not Configured”代码:403(Youtube api v3 shows “Access Not Configured” code:403)

我有类似的问题,它通过使用允许所有引用的浏览器密钥解决.. I had similar problem, It was solved by using browser key that allows all referers..

如何使用Google API PHP Client Library和Youtube API V3将视频上传到YouTube?(How to upload Video to YouTube using Google API PHP Client Library and Youtube API V3?)

奇怪的是,代码中的一个非常小的调整修复了这个问题。 而不是仅仅$videoPath = "/path/to/file.mp4"; 使用DOCUMENT_ROOT解决了这个问题。 除了那些文档代码是完美的。 $videoPath = $_SERVER["DOCUMENT_ROOT"] . "/mapapp/videos/test.mp4"; Strangely a very small tweak in code fixes the problem. Instead of just $videoP ...

回复:Youtube评级(Re: Youtube rating)

回答你的问题: https://www.googleapis.com/youtube/v3/videos/rate?id=gEqU0FMzPFo&rating=like&key=xxxx 这是您为视频评分所需的实际API帽子。 而另一个, https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.rateid=wtLJPvx7-ys&rating=like 我确信这只是一个API-Explorer站点,因此您

google youtube data api v3 youtube.videos.insert 503错误(google youtube data api v3 youtube.videos.insert 503 error)

503表示YouTube服务器后端出现暂时性错误。 现在它对我有用。 请再试一次。 503 means there was a transient error in YouTube server backend. Now it's working for me. Please try again.

如何使用youtube api v3获得YouTube视频的完整描述(how to get full description of youtube video using youtube api v3)

在文档中你会发现: 频道的说明最多可包含1000个字元。 要获得整个描述,您必须查询视频ID本身: https://www.googleapis.com/youtube/v3/videos?part=snippet&id={VIDEO_ID}&key={YOUR_API_KEY} 所以你必须做一些事情: $string = file_get_contents("https://www.googleapis.com/youtube/v3/search?part=snippet&channelId= ...

YouTube API v3:如何从PlaylistItems中返回404(未找到)错误?(YouTube API v3: How to get returned 404 (not found) error from PlaylistItems?)

如果您正在使用zend google api库,那么获取播放列表提要非常容易,并且可以捕获如果它不存在的任何错误,那么Google将返回该错误。 最简单的解决方案是获取帐户中所有播放列表的列表,并循环播放以查看播放列表ID是否与您拥有的ID匹配,然后从那里获取播放列表条目。 这样,真的不会有任何错误或例外。 但是,这是多次打电话,你试图避免。 为了进行一次通话,您需要拥有播放列表供稿网址,然后进行一次通话并捕获异常。 这些是我在使用YouTube播放列表时使用的几项功能的片段。 选项1: $thi ...

v3 Youtube API - 如何修改新广播的类别(v3 Youtube API - How to modify the category of a new broadcast)

您正在使用正确的资源,但方式错误。 1)你应该首先使用liveBroadcasts.insert()创建广播 2)然后使用您从该操作获得的广播/视频ID,您可以在该更新方法中调用videos.update(),您可以设置类别。 pseudocode: response = livebroadcast -> insert(broadcast); video = new video(); video.id = response.broadcastId; video->setCategory(25); ...

YouTube API v3获取与登录用户相关联的所有频道(YouTube API v3 get all channels associated with a logged in user)

OAuth2只允许一个频道登录,所以这是不可能的。 OAuth2已经允许用户选择他们想要授权并授予访问权限的渠道,因此您无需执行任何操作。 Found the answer in YouTube's API Blog here: http://apiblog.youtube.com/2013/06/google-page-identities-and-youtube-api.html According to this as I'm using Android with OAuth2 there ...

相关文章

更多

最新问答

更多
  • 使用javascript为用户延迟加载内容的更好方法是什么?(What is a better way to lazy load content for users with javascript?)
  • 如何修复无法将类型的值...转换为预期的参数类型inout _(How to fix Cannot convert value of type … to expected argument type inout _)
  • 从哪里开始解析JSON?(Where to start with parsing JSON?)
  • Mail.php不适用于.htaccess(Mail.php doesn't work with .htaccess)
  • 使用htaccess设置子域(Setting subdomains using htaccess)
  • mod_pagespeed和java应用服务器(mod_pagespeed and java app servers)
  • Win32:如何崩溃?(Win32: How to crash?)
  • FFmpeg中RGB到YUV转换的错误(Error in RGB to YUV conversion in FFmpeg)
  • 如何在Android中首次打开应用时创建弹出窗口?(How to create pop-up when first open app in Android?)
  • 通过动态传递表名和列名来反转COLUMN DATA(Reversing COLUMN DATA by dynamically passing table name and Column Name)
  • 如何计算C#中ICollection中有多少元素?(How can I count how many elements are in an ICollection in C#)
  • 从pg-promise查询中获得结果(get result out of a pg-promise query)
  • 使用管理器注册一个类,然后调用子类重写方法(Register a class with a manager, then call the sub classes overridden methods)
  • 传递&在查询字符串中(Passing & in query string)
  • 谷歌浏览器打印预览不会第一次加载页面(google chrome print preview does not load the page the first time)
  • FsLexYacc:Tests / MiniProject“在.fsproj中导入错误”(FsLexYacc : Tests/MiniProject “incorrect Import in .fsproj”)
  • 创建一个模型方法,计算用户的帖子并在rspec(Rails)中测试?(Create a model method that counts a user's posts and test in rspec (Rails)?)
  • 记录线程的奇怪行为(Strange behaviour of logging thread)
  • 移动数组中的索引(Moving indices in an array)
  • MVC 5 - > MVC 5.1迁移。(MVC 5 -> MVC 5.1 Migration. Intellisense issues)
  • 使用函数在z3中创建列表(Creating List in z3 using function)
  • 如何进行html随机重定向(How to make a html random redirect)
  • 角度js:使用角度过滤器分割日期,月份和时间(Angular js: spliting date,month and time using angular filter)
  • 将所有模块导入一个文件夹,并按其属性之一使用它们(Import all modules in one folder and use them by one of its attributes)
  • 只需要在git的当前分支上获得合并列表(Just get list of merge happened on my current branch in git)
  • React-Native导入库并在多个组件中可用(React-Native import a library and make available in multiple components)
  • 如何使用jQuery为固定(偏移)位置设置div动画?(How to animate div for a fixed (offset) position using jQuery?)
  • operator ==和vector confusion(operator== and vector confusion)
  • 如何获取所选图像映射alt值?(How to get selected image map alt value?)
  • 在角度,如何使用取消用户事件的美元间隔,如页面更改?(In angular, how to use cancel an $interval on user events, like page change?)