in iPhone App how to post Youtube video link using facebook graph Api to FaceBook Wall post?
Asked
Active
Viewed 2,260 times
2 Answers
0
Try this to post youtube video
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:accountType options:@{ACFacebookAppIdKey : facebookAppKey, ACFacebookPermissionsKey : [NSArray arrayWithObjects:@"publish_stream", nil], ACFacebookAudienceKey : ACFacebookAudienceOnlyMe} completion:^(BOOL granted, NSError *error) {
if(granted ) {
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
NSDictionary *postDict = @{
@"link": youtubeurl,//URL of youtube video
};
ACAccount *facebookAccount = [accountsArray objectAtIndex:0];
SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:@"https://graph.facebook.com/me/feed"]
parameters:postDict];
[facebookRequest setAccount:facebookAccount];
[facebookRequest performRequestWithHandler:^( NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error ) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.view setUserInteractionEnabled:true];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Posted Successfully on Facebook" message:@"" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
});
}];
} else {
NSLog(@"Error %@", error.description);
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Account not found" message:@"Please log in to Facebook account from Settings" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
});
}
}];

Nilesh Tupe
- 7,655
- 5
- 25
- 30
0
You can try this :
-(IBAction)postMeFeedButtonPressed:(id)sender {
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:@"#Your Message" forKey:@"message"];
[variables setObject:@"#http://Your Youtube Link" forKey:@"link"];
[variables setObject:@"#This is the bolded copy next to the image" forKey:@"name"];
[variables setObject:@"#This is the plain text copy next to the image. All work and no play makes Jack a dull boy." forKey:@"description"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/feed" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed: %@", fb_graph_response.htmlResponse);
//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
[parser release];
//let's save the 'id' Facebook gives us so we can delete it if the user presses the 'delete /me/feed button'
self.feedPostId = (NSString *)[facebook_response objectForKey:@"id"];
NSLog(@"feedPostId, %@", feedPostId);
NSLog(@"Now log into Facebook and look at your profile...");
}

Devang
- 11,258
- 13
- 62
- 100