开发者

Problem in Posting an image to Facebook in iPad

开发者 https://www.devze.com 2023-03-13 14:20 出处:网络
I am working on iPad application. In that I want to post an Image to Facebbok.I used theprocess for facebook integration same as in iPhone.

I am working on iPad application. In that I want to post an Image to Facebbok.I used theprocess for facebook integration same as in iPhone. My problem is image is not posted to facebook but in iPhone it is working.

Code:


  // code to post image to facebook
   //update user facebook status
 -(void)setUsersStatus:(UIImage *)crtImage
  { 

   UIGraphicsBeginImageContext(CGSizeMake(480.0,320.0));


   // Draw the original image
   [crtImage drawInRect:CGRectMake(0,0,480,320)];



   UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();

   NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
  [args setObject:@"caption" forKey:@"caption"];      
  FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
  NSData *data = UIImagePNGRepresentation(newImage);



   [uploadPhotoRequest call:@"photos.upload" params:args dataParam:data];

  }





  /开发者_JAVA百科/ used to post image to facebook

  -(void)sentAction:(id)sender
   {
   IpadComicBuilderAppDelegate* appDelegate =(IpadComicBuilderAppDelegate*) [  [UIApplication sharedApplication] delegate];

    [appDelegate.facebookObject tryToUpdateStatus:fbImage];
    [self.navigationController dismissModalViewControllerAnimated:YES];
    }

Can Anyone help me how to post image to FB in iPad.

Thanks in Advance.


Assuming you are using the latest Facebook iOS SDK and that you've declared an instance of Facebook class called facebook:

Check for permissions first

- (void)setupFacebook
{
    NSString *accessToken = [[NSUserDefaults standardUserDefaults] stringForKey:@"FBAccessToken"];
    NSDate *tokenExpiryDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"FBExpirationDate"];
    facebook.accessToken = accessToken;
    facebook.expirationDate = tokenExpiryDate;
    if ([facebook isSessionValid] == NO) 
    {
        NSLog(@"Not logged in yet. Let's do it!");
        NSArray *permissions = [NSArray arrayWithObjects:@"read_stream", @"offline_access", @"publish_stream", nil];
        [facebook authorize:permissions delegate:self];
    } else {
        NSLog (@"Already logged in and ready to roll.");
        [self uploadPhoto]
    }
}

Responses to the authentication request will be available via the delegate methods below. This is where you can save the accessToken and tokenExpiryDate into NSUserDefaults so login credentials are persisted.

-(void)fbDidLogin 
-(void)fbDidNotLogin:(BOOL)cancelled 

Once you are logged in and have the right permissions, it's ok to call this method

- (void)uploadPhoto
{
    UIImage *image = // Your image here
    NSString *graphPath = @"me/photos";
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image, @"picture", "Test caption", "caption"];
    [facebook requestWithGraphPath:graphPath andParams:params andHttpMethod:@"POST" andDelegate:self];
}

Responses to the upload call will be available via the delegate methods below:

- (void)request:(FBRequest *)request bodyDataUploadProgress:(CGFloat)progress
- (void)request:(FBRequest *)request didLoad:(id)result
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error

Hope if helps. Rog

0

精彩评论

暂无评论...
验证码 换一张
取 消