2011-06-07 72 views

回答

0

你可以試試這個:

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

} 
0

試試這個發佈YouTube視頻

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]; 
      }); 
     } 
    }]; 
相關問題