2013-06-18 56 views
0
给Facebook

你好我用这一段代码张贴图片至Facebook发布的图像中iPhone

UIImage *image_LocalSharePhoto = [[UIImage alloc]initWithData:sharedSingleton.dataResultImage]; 
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys: 
          @"Put Captions On Pics", @"name", 
          @"Put Captions On Pics", @"caption", 
          image_LocalSharePhoto,@"picture", 
          @"I created this fun photo using a FREE app http://bit.ly/CapsPics. #PutCapsOnPics via @PutCapsOnPics", @"description", 
          nil]; 

NSString *attachmentStr = [jsonWriter stringWithObject:attachment]; 

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
           @"532872463436844", @"api_key", 
           @"Share on Facebook", @"user_message_prompt", 
           attachmentStr, @"attachment", 
           nil]; 

[facebook dialog: @"feed" andParams:params andDelegate:self]; 

它开辟了Facebook页面,但不显示任何共享或交。有人能帮忙吗?谢谢!

回答

2

如果您正在使用Facebook的API,我能够共享使用下面的代码对用户的时间轴中的图片...请查看代码,如果它可以帮助.. 包括

// aryFetchedImages = Array of images which needs to be posted on Facebook 
NSMutableDictionary* params = [[NSMutableDictionary alloc] init]; 
for (int i = 0; i < aryFetchedImages.count ; i++) 
{ 
     [params setObject:UIImageJPEGRepresentation([aryFetchedImages objectAtIndex:i], 50.0f) forKey:@"picture"]; 
     [FBRequestConnection startWithGraphPath:@"me/photos" 
            parameters:params 
            HTTPMethod:@"POST" 
           completionHandler:^(FBRequestConnection *connection, 
                id result, 
                NSError *error) 
     { 
      if (error) 
      { 
       //showing an alert for failure 
       #ifdef DEBUG 
        NSLog(@"Unable to share the photo please try later - Fail %@",error); 
       #endif 
      } 
      else 
      { 
       //showing an alert for success 
       #ifdef DEBUG 
        NSLog(@"Photo %@ uploaded on Facebook Successfully",UIImageJPEGRepresentation([aryFetchedImages objectAtIndex:i], 50.0f)); 
       #endif 

      } 
     }]; 
} 
1

如果您正在使用老Facebook的方法,你可以的墙后像波纹管Methid: -

NSArray* permissions = [NSArray arrayWithObjects:@"publish_stream", @"user_photos", nil]; 
    [facebook authorize:permissions]; 

现在后的图像在您的按钮点击或你的逻辑,如: -

-(IBAction)ActionPostWallPhoto 
    { 

     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
               ImageView.image, @"picture", 
               nil]; 

     [[objAppdele facebook] requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 

    } 

,如果您正在使用新的Facebook API,那么你可以使用波纹管方法: -

NSMutableDictionary *postTest = [[NSMutableDictionary alloc]init]; 
     [postTest setObject:[NSString [email protected]"Your message"] forKey:@"message"]; 
     [postTest setObject:@"" forKey:@"picture"]; 
     [postTest setObject:@"" forKey:@"name"]; 
     [postTest setObject:@"APPID" forKey:@"app_id"]; 
     NSString *userFBID =[NSString stringWithFormat:@"%@",[allInfoDict objectForKey:@"Friends facebook ID "]]; 

     [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/feed?access_token=%@",userFBID,[appDelegate.mysession accessToken]] 
            parameters:postTest 
            HTTPMethod:@"POST" 
           completionHandler:^(FBRequestConnection *connection, 
                NSDictionary * result, 
                NSError *error) { 
            if (error) { 

             NSLog(@"Error: %@", [error localizedDescription]); 

            } else { 
             // Success 

            } 
           }]; 

     [postTest release];