流到Facebook Live API无法正常工作?

时间:2019-06-18 12:22:50

标签: swift xcode

我已经在我的iOS应用中集成了Facebook实时流媒体,并且以前可以正常运行,但是从5月1日开始不起作用。有人可以帮助我解决此问题。

以下是五月之前的工作代码: func start(){

    guard FBSDKAccessToken.current().hasGranted("publish_video") else {
        return self.delegate.liveVideo(self, didErrorWith: FBSDKLiveVideo.errorFromDescription(description: "The \"publish_video\" permission has not been granted"))
    }
    print("Parameters : \(self.audience)")
    let graphRequest = FBSDKGraphRequest(graphPath: "/\(self.audience)/live_videos", parameters: self.createParameters, httpMethod: "POST")
   // let m=FBSDKAccessToken.current().appID
    DispatchQueue.main.async {
        _ = graphRequest?.start { (_, result, error) in
            guard error == nil, let dict = (result as? NSDictionary) else {
                return self.delegate.liveVideo(self, didErrorWith: FBSDKLiveVideo.errorFromDescription(description: "Error initializing the live video session: \(String(describing: error?.localizedDescription))"))
            }

            self.url = URL(string:(dict.value(forKey: "stream_url") as? String)!)
            self.id = dict.value(forKey: "id") as? String
            self.videoId = dict.value(forKey: "id") as? String
            guard let streamPath = self.url?.lastPathComponent, let query = self.url?.query else {
                return self.delegate.liveVideo(self, didErrorWith: FBSDKLiveVideo.errorFromDescription(description: "The stream path is invalid"))
            }

            self.session.startRtmpSession(withURL: "rtmp://rtmp-api.facebook.com:80/rtmp/", andStreamKey: "\(streamPath)?\(query)") 

            self.delegate.liveVideo(self, didStartWith:self.session)
        }
    }
}

我也曾问过这个问题,Facebook支持团队建议他们使用rtmps,然后我更新了如下代码,但也无法正常工作:  func start(){

    guard FBSDKAccessToken.current().hasGranted("publish_video") else {
        return self.delegate.liveVideo(self, didErrorWith: FBSDKLiveVideo.errorFromDescription(description: "The \"publish_video\" permission has not been granted"))
    }
    print("Parameters : \(self.audience)")
    let graphRequest = FBSDKGraphRequest(graphPath: "/\(self.audience)/live_videos", parameters: self.createParameters, httpMethod: "POST")
   // let m=FBSDKAccessToken.current().appID
    DispatchQueue.main.async {
        _ = graphRequest?.start { (_, result, error) in
            guard error == nil, let dict = (result as? NSDictionary) else {
                return self.delegate.liveVideo(self, didErrorWith: FBSDKLiveVideo.errorFromDescription(description: "Error initializing the live video session: \(String(describing: error?.localizedDescription))"))
            }

            self.url = URL(string:(dict.value(forKey: "stream_url") as? String)!)
            self.id = dict.value(forKey: "id") as? String
            self.videoId = dict.value(forKey: "id") as? String
            guard let streamPath = self.url?.lastPathComponent, let query = self.url?.query else {
                return self.delegate.liveVideo(self, didErrorWith: FBSDKLiveVideo.errorFromDescription(description: "The stream path is invalid"))
            }
            self.session.startRtmpSession(withURL: "rtmps://live-api-s.facebook.com:443/rtmp/", andStreamKey: "\(streamPath)?\(query)")
            self.delegate.liveVideo(self, didStartWith:self.session)
        }
    }
}

不醒,任何人都可以帮助我解决此问题。

0 个答案:

没有答案