我有一个应用程序,我曾经能够登录谷歌帐户,然后将视频上传到该帐户。但是应用程序包 ID 发生了变化,我不得不更新到 googleSignIn。
所以现在当我打开 View Controller 时,我想上传视频,我有一个谷歌登录按钮,用户点击并登录并选择让应用程序访问范围:
googleapis.com/auth/youtube
googleapis.com/auth/youtube.upload
googleapis.com/auth/youtubepartner
googleapis.com/auth/youtube.force-ssl
我还更新了应用程序开发人员 key
所以我现在有一个开发人员 key 和一个客户端 ID,我用应用程序中的旧 key 替换了以下代码
- (GTMOAuth2Authentication *)authForDailyMotion {
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:kGDataServiceDefaultUser];
NSString *redirectURI = @"http://www.google.com/OAuthCallback";
NSString *clientID = @"552XXXXXXXX3-banchtj9877k4o4noj32eu1h5jokctu0.apps.googleusercontent.com";
NSString *clientSecret = devKey;
GTMOAuth2Authentication *auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"my little world"
tokenURL:url
redirectURI:redirectURI
clientID:clientID
clientSecret:clientSecret];
return auth;
}
用户登录谷歌后,他们会被带到一个页面,该页面显示应用程序正在请求访问权限
管理 YouTube 帐户
查看和管理 Youtube 上的 Assets 和相关内容
管理 youtube 视频
当用户当前点击“允许”按钮时,他们将被带到 google.com,在那里他们可以从设备上的相机胶卷上传视频和其他内容。
我希望将用户重定向回应用程序中的查看者可以查看的 View
输入标题,描述,标签,选择一个类别,并选择其隐私,然后使用直接从应用程序发布视频
- (void)uploadVideoFile {
NSString *audioName = [pictureDictionary4 objectForKey:@"photoVideokey"];
NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorya = [pathsa objectAtIndex:0];
NSString *moviePath = [documentsDirectorya stringByAppendingPathComponent:@"/Movie"];
//Get a full path to the image in the documents directory.
NSString *fullPatha = [moviePath stringByAppendingPathComponent:audioName];
GDataServiceGoogleYouTube *service = [self youTubeService];
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:kGDataServiceDefaultUser];
NSString *filename = audioName;
NSData *data = [NSData dataWithContentsOfFile:fullPatha];
GDataYouTubeMediaGroup *media = [GDataYouTubeMediaGroup mediaGroup];
[media setMediaTitle:title];
[media setMediaDescription:desc];
[media addMediaCategory:category];
[media setMediaKeywords:keywords];
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:fullPatha
defaultMIMEType:@"video/mp4"];
GDataEntryYouTubeUpload *entry;
entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:media
/*fileHandle:fileHandle*/
data:data
MIMEType:mimeType
slug:filename];
GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:entry
forFeedURL:url
delegate:self
didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];
[self setUploadTicket:ticket];
GTMHTTPUploadFetcher *uploadFetcher = (GTMHTTPUploadFetcher *)[ticket objectFetcher];
[uploadFetcher setLocationChangeBlock:^(NSURL *url) {
[self setUploadLocationURL:url];
通过点击“发布”
我认为需要更改重定向 url,以便将身份验证提供给应用程序,然后用于上传视频。但是我不确定
现在,如果用户点击完成按钮并返回应用程序并输入上述信息并点击“发布”
我收到以下错误。
upload failed: Error Domain=com.google.HTTPStatusCode=401 *(User authentacation required)
我认为这是因为授权只允许在线上传,而不是通过应用程序。
有人可以告诉我我在这个假设中是否正确,那么我如何在点击“允许”后将用户重定向回应用程序以上传视频
如果我的假设不正确,有人可以给我一些指导,告诉我如何按照我的意愿完成这项工作。
最佳答案
关于ios - 从更新的 Xcode 应用程序将视频上传到 youtube,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34502844/