我正在嘗試使用youtube api示例代碼上傳視頻。 當我按上傳按鈕,進度條完成其進程,但一旦達到點的結束,我會得到錯誤。錯誤說明如下:Youtube API身份驗證 - Iphone
YouTubeTest [2149:F803]。錯誤 - 錯誤 域= com.google.GDataServiceDomain代碼= 400「的操作不能 完成(com.google.GDataServiceDomain誤差400 。)」 的UserInfo = 0x69d5bd0 {}
這是上傳按鈕按下代碼
- (IBAction)uploadPressed:(id)sender {
[self.view resignFirstResponder];
NSString *devKey = [mDeveloperKeyField text];
GDataServiceGoogleYouTube *service = [self youTubeService];
[service setYouTubeDeveloperKey:devKey];
NSString *username = [mUsernameField text];
NSString *clientID = [mClientIDField text];
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username
clientID:clientID];
// load the file data
NSString *path = [[NSBundle mainBundle] pathForResource:@"YouTubeTest" ofType:@"m4v"];
NSData *data = [NSData dataWithContentsOfFile:path];
NSString *filename = [path lastPathComponent];
// gather all the metadata needed for the mediaGroup
NSString *titleStr = [mTitleField text];
GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];
NSString *categoryStr = [mCategoryField text];
GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr];
[category setScheme:kGDataSchemeYouTubeCategory];
NSString *descStr = [mDescriptionField text];
GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];
NSString *keywordsStr = [mKeywordsField text];
GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr];
BOOL isPrivate = mIsPrivate;
GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
[mediaGroup setMediaTitle:title];
[mediaGroup setMediaDescription:desc];
[mediaGroup addMediaCategory:category];
[mediaGroup setMediaKeywords:keywords];
[mediaGroup setIsPrivate:isPrivate];
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:path
defaultMIMEType:@"video/mp4"];
// create the upload entry with the mediaGroup and the file data
GDataEntryYouTubeUpload *entry;
entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
data:data
MIMEType:mimeType
slug:filename];
SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
[service setServiceUploadProgressSelector:progressSel];
GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:entry
forFeedURL:url
delegate:self
didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];
[self setUploadTicket:ticket];
}
我已經從API設置顯影劑密鑰和客戶端密鑰正確儀表板。
我在模擬器上運行這個。難道我們不能從模擬器上傳視頻嗎?
請指導我在哪裏出錯?
400錯誤通常意味着錯誤的請求。我會檢查您的所有代碼,登錄身份驗證,如果可能,請在設備上進行測試以排除模擬器可能導致的任何可能的問題。 – Luke
@Luke我也在設備上檢查過它。它不工作那裏要麼..給相同的錯誤:( – innodeasapps
你有任何示例代碼或鏈接,然後請share.I爲Mac OS X的樣品,但爲iOS的機器人。 – Imran