我正在制作测试应用程序,因为我想在Facebook上发布视频。我正在使用Facebook最新的sdk。但是我无法在Facebook上发布它。该视频来自网络服务 如何在nsdata和mu代码中转换视频网址
NSString *astrUserid=[[mutTimeline objectAtIndex:indexpath] objectForKey:@"user_id"];
NSString *astrImageid=[[mutTimeline objectAtIndex:indexpath] objectForKey:@"image_id"];
NSString *astrExt=[[mutTimeline objectAtIndex:indexpath] objectForKey:@"ext"];
NSString *aStrDisplyimage=[NSString stringWithFormat:@"http://followme.pmcommu.com/audio/user/%@-%@.%@",astrUserid, astrImageid,astrExt ];
NSURL *aimageurl=[NSURL URLWithString:aStrDisplyimage];
NSString *filePathOfVideo = [aimageurl path];
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);
}
}];
}
}];
}
我是新手,任何人都可以帮助我
答案 0 :(得分:0)
获取发布权限
NSArray* permissions = [[NSArray alloc] initWithObjects:
@"publish_stream", nil];
[facebook authorize:permissions delegate:self];
[permissions release];
试试这个
- (void)fbDidLogin {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" 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];
}
答案 1 :(得分:0)
或者这将有助于您上传和流式传输视频,我认为
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// Specify App ID and permissions
NSDictionary *options = @{ACFacebookAppIdKey: FACEBOOK_ID,
ACFacebookPermissionsKey: @[@"publish_stream", @"video_upload"],
ACFacebookAudienceKey: ACFacebookAudienceFriends}; // basic read permissions
[accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *e) {
if (granted) {
NSArray *accountsArray = [accountStore accountsWithAccountType:facebookAccountType];
if ([accountsArray count] > 0) {
ACAccount *facebookAccount = [accountsArray objectAtIndex:0];
NSDictionary *parameters = @{@"description": aMessage};
SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:@"https://graph.facebook.com/me/videos"]
parameters:parameters];
[facebookRequest addMultipartData: aVideo
withName:@"source"
type:@"video/mp4"
filename:@"video.mov"];
facebookRequest.account = facebookAccount;
[facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
if (error == nil) {
NSLog(@"responedata:%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}else{
NSLog(@"%@",error.description);
}
}];
}
} else {
NSLog(@"Access Denied");
NSLog(@"[%@]",[e localizedDescription]);
}
}];
答案 2 :(得分:0)
试试这个
[NSData dataWithContentsOfURL:[NSURL URLWithString:@"Your URL"]]
答案 3 :(得分:0)
-(void)facbookSharng {
NSLog(@"Permission for sharing..%@",[FBSDKAccessToken currentAccessToken].permissions);
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"contact_email"])
{
FBSDKShareVideo *ShareVideo = [FBSDKShareVideo videoWithVideoURL:appDelegateObj.finalVideoUrl];
ShareVideo.videoURL = appDelegateObj.finalVideoUrl;
FBSDKShareVideoContent *ShareContnt = [[FBSDKShareVideoContent alloc] init];
ShareContnt.video = ShareVideo;
[FBSDKShareAPI shareWithContent:ShareContnt delegate:self]
// write the deleate methdo for post ID..
}