0

iPhone から Facebook に動画をアップロードしようとしています。FBLoginView を使用してログインし、FBSession を作成しました。次のコードを使用して、ビデオのアップロードの FBRequest を開始しました。

- (void)buttonRequestClickHandler:(id)sender {

if (FBSession.activeSession.isOpen) {

    [FBSession.activeSession requestNewPublishPermissions:permissions
                                    defaultAudience:FBSessionDefaultAudienceOnlyMe
                                        completionHandler:nil];        

    NSString *audioName = [pictureDictionary4 objectForKey:@"photoVideokey"];
    NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectorya = [pathsa objectAtIndex:0];
    NSString *moviePath = [documentsDirectorya stringByAppendingPathComponent:@"/Movie"];
    NSString *fullPatha = [moviePath stringByAppendingPathComponent:audioName];
    NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:fullPatha isDirectory:NO];
    NSData *videoData = [NSData dataWithContentsOfFile:fullPatha];

    NSString *titleString = self.videotitle.text;
    NSString *descripString = self.descrp.text;

    NSDictionary *videoObject = @{
                                  @"title":titleString,
                                  @"description": descripString,
                                  [pathURL absoluteString]: videoData
                                  };
    FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos"
                                                    parameters:videoObject
                                                    HTTPMethod:@"POST"];

   [uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        if (!error)
            NSLog(@"Done: %@", result);
        else
            NSLog(@"Error: %@", error.localizedDescription);
    }];
}

エラー Error: The operation could not be completed. が表示されます。(com.facebook.sdk エラー 5.)

エラーが何に関係するのかわかりません:

私はログインしていることを知っています

接続されているかどうかわかりませんが、iPhone でインターネットに接続しています

パラメータが間違っていますか? 私は何時間もこれをいじっていますが、結果はありません。誰からの助けも大歓迎です。

最後に、iPhone の設定 - Facebook に移動し、アカウントを削除することで、これが機能するようになりました。次に、自分のアプリでビデオをアップロードするためにタップすると、Facebook が自分のアプリを使用できるかどうかを尋ねるビューが読み込まれ、「はい」と答えてアップロードを禁止しました。また、権限を publish_actions のみに変更し、publish_streams を削除する必要がありました。これは読み取り権限であるためです。とにかくそれは今働いています。次に、ハードコーディングされていない、ユーザーが選択した文字列からロードする defaultAudience を取得します。別の投稿。

4

2 に答える 2

0

ストリームの公開許可と関係があると思います。この方法を試してください。それは私のために働いた。Facebook SDK 3.8.0 を使用していました

    [self performPublishAction:^{

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"faisal" ofType:@"mov"];
    NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO];
    NSData *videoData = [NSData dataWithContentsOfFile:filePath];

    NSDictionary *videoObject = @{
                                  @"title": @"This is my title",
                                  @"description": @"This is my description",
                                  [pathURL absoluteString]: videoData
                                  };
    FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos"
                                                    parameters:videoObject
                                                    HTTPMethod:@"POST"];

    [uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        if (!error)
            NSLog(@"Done: %@", result);
        else
            NSLog(@"Error: %@", error.localizedDescription);
    }];
}];

- (void) performPublishAction:(void (^)(void)) action {
if ([FBSession.activeSession.permissions indexOfObject:@"publish_stream"] == NSNotFound) {
    [FBSession.activeSession requestNewPublishPermissions:@[@"publish_stream"]
                                          defaultAudience:FBSessionDefaultAudienceFriends
                                        completionHandler:^(FBSession *session, NSError *error) {
                                            if (!error) {
                                                action();
                                            } else if (error.fberrorCategory != FBErrorCategoryUserCancelled){
                                                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Permission denied"
                                                                                                    message:@"Unable to get permission to post"
                                                                                                   delegate:nil
                                                                                          cancelButtonTitle:@"OK"
                                                                                          otherButtonTitles:nil];
                                                [alertView show];
                                            }
                                        }];
} else {
    action();
}
}
于 2013-09-23T11:29:30.130 に答える
0

このコードは、FaceBook SDK 3.14.1で正常にテストされています

推奨: .plist ファイルの 3 つのプロパティ

FacebookAppID、FacebookDisplayName を設定し、
URL タイプ -> アイテム 0 -> URL スキームを facebookappId プレフィックスにfb 設定

-(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:

  • セッションは開いていません。検証。
  • Facebook は、あなたがシステムにスパム行為を行っていることを検出しました。動画名変更。
  • Facebook には、SDK を使用した制限が定義されています。別のアプリを試してください。
  • 公開許可が間違っています。publish_actionsスピンしてください。
于 2014-06-28T14:17:32.820 に答える