試驗成功論FaceBook SDK 3.14.1
建議:在的.plist文件 3個屬性
集FacebookAppID,FacebookDisplayName,
URL類型 - >物品0-> URL方案設置爲facebookappId前綴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.)
被inited的Facebook時,它發生。下次我打開我的應用程序,它工作正常,它總是第一次。嘗試了應用程序中的所有內容,但似乎在Facebook SDK一側。
幾個原因看到com.facebook.sdk error 5
:
- 會議是不開放的。驗證。
- Facebook檢測到您發送垃圾郵件。更改視頻名稱。
- Facebook使用SDK定義了一個限制。嘗試不同的應用程序。
- 錯誤的發佈權限。給
publish_actions
一個旋轉。
- 更多....
看到圖片並從那裏下載。你只能在其中設置facebook appid。 –