Facebook Live Video API,我可以通过编程方式分享朋友视频流吗?

时间:2016-04-13 11:02:03

标签: ios facebook facebook-graph-api video

我想以编程方式在自己的墙上分享Facebook视频直播。在使用facebook sdk进行Facebook登录后,我希望在我的应用程序中执行此操作,类似于正常的链接共享:

 NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
 [params setObject:link forKey:@"picture"];
 [params setObject:LinkStringa forKey:@"link"];
 [params setObject:ShareTextView.text forKey:@"message"];
 [params setObject:[[FBSDKAccessToken currentAccessToken] tokenString] forKey:@"access_token"];

  FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                initWithGraphPath:@"/me/feed"
                                parameters:params
                                HTTPMethod:@"POST"];
  [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                              id result,
                                              NSError *error) {

      // Handle the result
      if (!error) {



      }
      else{
          NSLog(@"error %@",error.description);
      }

  }];

我无法找到关于在Facebook文档上分享实时视频的提及,仅提及如何创建和发布实时视频。我如何分享直播视频?

3 个答案:

答案 0 :(得分:2)

您可以使用此方法:

- (void)enableFacebookLiveStreamingWithCompletionHandler:(void(^)(NSString* facebookStreamURL, NSString* facebookStreamKey, NSError* error))completionHandler;
{
    dispatch_async(dispatch_get_main_queue(), ^{
        if ([[FBSDKAccessToken currentAccessToken] hasGranted:permissionPublishActions])
        {
            NSString* liveVideosRequestPath = [NSString stringWithFormat:@"/%@/live_videos",[FBSDKAccessToken currentAccessToken].userID];
            FBSDKGraphRequest* request = [[FBSDKGraphRequest alloc] initWithGraphPath:liveVideosRequestPath parameters:nil HTTPMethod:@"POST"];

            [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

                NSLog(@"%@",[FBSDKAccessToken currentAccessToken].permissions);

                if (error)
                {
                    if (completionHandler)
                        completionHandler(@"",@"",error);
                }
                else
                {
                    if (completionHandler)
                        completionHandler(@"rtmp://rtmp-api.facebook.com:80/rtmp/",[[result objectForKey:@"stream_url"] lastPathComponent],nil);
                }

            }];
        }
    });
}

对于通过RTMP进行流式传输,请使用此开源库:https://github.com/jgh-/VideoCore

有一个代码例如:

self.vcSession = [[VCSimpleSession alloc] initWithVideoSize:CGSizeMake(854, 480) frameRate:30 bitrate:1000000 useInterfaceOrientation:NO];
[self.view addSubview:self.vcSession.previewView];
self.vcSession.previewView.frame = CGRectMake(40, 40, 320, 240);//self.view.bounds;
self.vcSession.delegate = self;
[self.vcSession startRtmpSessionWithURL:@"your rtmp:URL "andStreamKey:@"your stream key"];

答案 1 :(得分:1)

Swift 3

你可以查看这个回购

https://github.com/hansemannn/facebook-live-ios

如何使用

var liveVideo: FBSDKLiveVideo!

override func viewDidLoad() {
    super.viewDidLoad()

    // Create the live video service
    liveVideo = FBSDKLiveVideo(
        delegate: self,
        previewSize: self.view.bounds,
        videoSize: CGSize(width: 1280, height: 720)
    )

    // Optional: Configure the live-video (see the source for all options)
    liveVideo.privacy = .me // or .friends, .friendsOfFriends, .custom
    liveVideo.audience = "me" // or your user-id, page-id, event-id, group-id, ...

    // Optional: Add the preview view of the stream to your container view.
    myView.addSubView(liveVideo.preview)
}

enter image description here

答案 2 :(得分:0)

找到此链接https://developers.facebook.com/docs/videos/live-video-api,其中说明:

“直播视频

创建live_video对象后,将在响应中返回stream_url和key。服务器URL将为http://rtmp-api.facebook.com/rtmp/,流密钥将是其后的所有内容。使用这两种方法可以通过流媒体软件推送视频帧。“

让我知道结果如何,因为我也正在启动具有此功能的应用程序。