IPhone app how to send Youtube video link using facebook graphics Api

in iPhone app, how to post YouTube Youtube link using facebook Api graphics on FaceBook Wall post?


source to share

2 answers

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 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...");





Try to post a 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
                                                                      URL:[NSURL URLWithString:@"https://graph.facebook.com/me/feed"]

            [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];




All Articles