簡體   English   中英

iphone sdk 上傳視頻到 facebook

[英]iphone sdk upload video on facebook

我正在嘗試使用 FBConnect 從 iPhone 應用程序上傳視頻。 其實我已經嘗試了幾種方法,但不幸的是沒有任何成功。

第一的。 使用“ facebook.video.upload ”REST 方法和技巧在這里描述iPhone Facebook 視頻上傳 結果服務器返回一個空響應,之后會發生更多事情。 facebook 上未顯示視頻。 順便嘗試了不同類型的 facebook 應用程序,例如 WebApp 和 Native 一個。

第二。 使用“我/視頻” GRAPH 方法和下面的代碼來啟動上傳

>

     NSMutableDictionary *params = [NSMutableDictionary
 dictionaryWithObjectsAndKeys:movieData,
 @"source", @"File.mov", @"filename",
 nil];
 [m_facebook requestWithGraphPath:@"me/videos"

andParams:params andHttpMethod:@"POST" andDelegate:self];

在這種情況下,我會收到下一個錯誤:

a) 必須使用活動訪問令牌來查詢有關當前用戶的信息。

b) 不支持視頻文件格式。

第三。 只需發送 email 並附上視頻文件到 video@facebook.com。 不工作。 然而,這個解決方案不像以前那樣感興趣。

我花了 2 天時間弄清楚這些事情,這讓我發瘋。 有人可以分享一個視頻上傳的工作示例,或者至少指出我在樣本中的錯誤所在。

謝謝!

您應該使用 Graph 方法,因為舊的 API 已被棄用,並且 go 將在不久的將來某個時候消失。 因此,我會解決這個問題。

第一個問題是您不能在沒有登錄的情況下將視頻上傳到 Facebook。 您需要按照以下說明獲取訪問令牌,然后才能上傳視頻: http://developers.facebook.com/docs/authentication

您還需要upload_video權限,由於某種原因,該權限未在“權限”頁面上列出。

我不確定第二個問題,但 Facebook 支持多種視頻格式 大概您的視頻是其中一種可能受支持的 Apple 格式。 修復第一個問題,看看是否對第二個問題有任何影響。

NSURL *urlvideo = [info objectForKey:UIImagePickerControllerMediaURL];
NSString *urlString=[urlvideo path];

NSLog(@"urlString=%@",urlString);
NSString *str = [NSString stringWithFormat:@"you url of server"];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setFile:urlString forKey:@"key foruploadingFile"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request startSynchronous];
NSLog(@"responseStatusCode %i",[request responseStatusCode]);
NSLog(@"responseStatusCode %@",[request responseString]);

從官方 Facebook 開發者網站上找到簡單的資源用於上傳視頻。

他們有點老,但仍然工作正常。 http://developers.facebook.com/attachment/VideoUploadTest.zip也許這個來源會對某人有所幫助。 但不要忘記將 AppID 更改為您的。 我在 3 個地方成功了

facebook = [[Facebook alloc] initWithAppId:@"..."]; 和 plist 文件中的 2 個屬性 - FacebookAppID、URL 類型數組http://i.stack.imgur.com/yZAXQ.png

- (IBAction)buttonClicked:(id)sender {
     NSArray* permissions = [[NSArray alloc] initWithObjects:
                        @"publish_stream", nil];
[facebook authorize:permissions delegate:self];
[permissions release];
}

- (void)fbDidLogin {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"buf-3" ofType:@"mov"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               videoData, @"video.mov",
                               @"video/quicktime", @"contentType",
                               @"Video Test Title", @"title",
                               @"Video Test Description", @"description",
                               nil];
[facebook requestWithGraphPath:@"me/videos"
                     andParams:params
                 andHttpMethod:@"POST"
                   andDelegate:self];
}

祝你好運!

此代碼在FaceBook SDK 3.14.1上測試成功

推薦: .plist文件中的3個屬性

設置 FacebookAppID、FacebookDisplayName、
URL types->Item 0-> URL Schemes set to facebookappId prefix with fb See

-(void)shareOnFaceBook
{
    //sample_video.mov is the name of file
    NSString *filePathOfVideo = [[NSBundle mainBundle] pathForResource:@"sample_video" ofType:@"mov"];

    NSLog(@"Path  Of Video is %@", filePathOfVideo);
    NSData *videoData = [NSData dataWithContentsOfFile:filePathOfVideo];
    //you can use dataWithContentsOfURL if you have a Url of video file
    //NSData *videoData = [NSData dataWithContentsOfURL:shareURL];
    //NSLog(@"data is :%@",videoData);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               videoData, @"video.mov",
                               @"video/quicktime", @"contentType",
                               @"Video name ", @"name",
                               @"description of Video", @"description",
                               nil];

   if (FBSession.activeSession.isOpen)
   {
        [FBRequestConnection startWithGraphPath:@"me/videos"
                                 parameters:params
                                 HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                              if(!error)
                              {
                                  NSLog(@"RESULT: %@", result);
                                  [self throwAlertWithTitle:@"Success" message:@"Video uploaded"];
                              }
                              else
                              {
                                  NSLog(@"ERROR: %@", error.localizedDescription);
                                  [self throwAlertWithTitle:@"Denied" message:@"Try Again"];
                              }
                          }];
    }
    else
    {
        NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"publish_actions",
                            nil];
        // OPEN Session!
        [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone  allowLoginUI:YES
                                     completionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error) {
                                         if (error)
                                         {
                                             NSLog(@"Login fail :%@",error);
                                         }
                                         else if (FB_ISSESSIONOPENWITHSTATE(status))
                                         {
                                             [FBRequestConnection startWithGraphPath:@"me/videos"
                                                                          parameters:params
                                                                          HTTPMethod:@"POST"
                                                                   completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                                                       if(!error)
                                                                       {
                                                                           [self throwAlertWithTitle:@"Success" message:@"Video uploaded"];

                                                                           NSLog(@"RESULT: %@", result);
                                                                       }
                                                                       else
                                                                       {
                                                                           [self throwAlertWithTitle:@"Denied" message:@"Try Again"];

                                                                           NSLog(@"ERROR: %@", error.localizedDescription);
                                                                       }

                                                                   }];
                                         }
                                     }];
        }
}

第一次運行應用程序時出現錯誤:

 The operation couldn’t be completed. (com.facebook.sdk error 5.)

它發生在 facebook 被初始化時。 下次我打開我的應用程序時,它運行良好,它總是第一次。 嘗試了應用程序中的所有內容,但它似乎在 Facebook SDK 方面。

看到com.facebook.sdk error 5的幾個原因:

  • Session 未打開。 證實。
  • Facebook 檢測到您正在向系統發送垃圾郵件。 更改視頻名稱。
  • Facebook 使用 SDK 具有定義的限制。 嘗試不同的應用程序。
  • 錯誤的發布權限。 publish_actions一個旋轉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM