【问题标题】:iPhone App how to post Youtube video link using facebook graph ApiiPhone App 如何使用 facebook graph Api 发布 Youtube 视频链接
【发布时间】:2011-06-07 05:38:21
【问题描述】:

在 iPhone 应用程序中如何使用 facebook graph Api 将 Youtube 视频链接发布到 FaceBook Wall 帖子?

【问题讨论】:

    标签: iphone objective-c cocoa-touch ios4 facebook-graph-api


    【解决方案1】:

    你可以试试这个:

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

    【讨论】:

      【解决方案2】:

      试试这个来发布 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];
                  });
              }
          }];
      

      【讨论】:

        猜你喜欢
        • 2011-04-16
        • 2011-07-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-24
        • 1970-01-01
        • 2013-06-18
        • 1970-01-01
        相关资源
        最近更新 更多