在应用程序内设置 YouTube 访问,卡在检索 url 响应上 [英] Setting up YouTube access within app, stuck on retrieving url response

查看:24
本文介绍了在应用程序内设置 YouTube 访问,卡在检索 url 响应上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到有关 YouTube API 难题的任何答案或类似问题,希望有人能提供帮助.

I can't find any answers or similar questions to my YouTube API puzzle and hoping someone can help.

我的 iOS 应用在其中制作视频,需要连接到用户的 YouTube 帐户,以便他们可以上传视频供其他人观看等.

My iOS app, which makes a video within it, needs to connect to a user's YouTube account so they can upload the video for others to see etc.

我遵循 API 文档并设法连接到用户登录其帐户的身份验证部分(我在下面发布的代码).

I've followed the API documentation and managed to connect to the authentication part where the user logs into their account, (code I used posted below).

它的工作原理是将用户带到 Google 的登录页面,登录页面时会询问用户是否要授权应用程序访问帐户等.当用户接受时,我明白应该有返回的数据为应用程序提供身份验证和令牌代码,以便稍后在应用程序中上传视频.

It works in the sense it takes user to the login page for Google, when logged in the page asks if the user would like to authorise the app access to account, etc. When the user accepts though, I understand there should be data returned which gives the app authentication, the token code, so it can be used to upload videos later within the app.

我的问题是......我如何检索这些数据?当我点击接受时,它只会将我带到另一个网页,但我不知道从哪里检索信息.

My question is.... How do I retrieve this data? When I click accept it simply takes me to another webpage, but I don't know where to retrieve the info.

提前感谢任何能指出我正确方向的人.

Thanks in advance for anyone who can point me in the right direction.

#define kAuthUrl @"https://accounts.google.com/o/oauth2/auth?"
#define kClientID @"client_id=xxxxxxxxxxxMyUniqueIDDetailsxxxxxxxxxx&" 
#define kRediretUri @"redirect_uri=urn:ietf:wg:oauth:2.0:oob&"
#define kScopeUL @"scope=https://www.googleapis.com/auth/youtube.upload&"
#define kResponse @"response_type=code"

以上代码放在头文件中.

Above code placed in header file.

- (void)viewDidLoad

{

NSString *loginURL = [NSString stringWithFormat:@"%@%@%@%@%@", kAuthUrl, kClientID, kRediretUri, kScopeUL, kResponse]; 

NSURLRequest * urlReq = [NSURLRequest requestWithURL: [NSURL URLWithString:loginURL]];

[_webView loadRequest:urlReq];

[super viewDidLoad];
// Do any additional setup after loading the view.

}

从 YouTube API 文档说

From the YouTube API documentation it says

使用此值时,您的应用程序可以感知页面已加载并且 HTML 页面的标题包含授权代码.如果您想确保用户永远不会看到包含授权代码的页面,则由您的应用程序关闭浏览器窗口.执行此操作的机制因平台而异.

When this value is used, your application can sense that the page has loaded and the title of the HTML page contains the authorization code. It is then up to your application to close the browser window if you want to ensure that the user never sees the page that contains the authorization code. The mechanism for doing this varies from platform to platform.

其中这个值"是指我选择的 redirect_uri,而不是本地主机重定向.

Where "this value" refers to the redirect_uri I chose, as opposed to a local host redirect.

我怎么能感觉到用户已经登录到他们的帐户并按下了接受"按钮,这现在也让我询问如何知道这一点,然后在关闭浏览器的同时从返回的 url 中检索代码.

How can I sense the user has logged on to their account and pressed the "accept" button, and this now also leads me on to asking how to know this and then retrieve the code from the returned url while closing the browser.

干杯,吉姆.

推荐答案

我强烈建议使用 Google Toolbox for Mac OAuth 2 Controllers 项目为您处理 OAuth 2 集成的所有细节.

My strong recommendation is to use the Google Toolbox for Mac OAuth 2 Controllers project to handle all the details of your OAuth 2 integration for you.

这篇关于在应用程序内设置 YouTube 访问,卡在检索 url 响应上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆