简体   繁体   中英

Facebook Graph API Upload Photo Problem

I've searched all through the web and have downloaded the Facebook SDK thing to try out the upload photo function and it worked there. Exact same codes over to my application and it doesn't work. Help please??? These are my codes:

- (IBAction)pushUpload:(id)sender {

    NSString *path = @"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg";
    NSURL *url = [NSURL URLWithString:path];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *img  = [[UIImage alloc] initWithData:data];

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   img, @"picture",
                                   nil];

    [_facebook requestWithGraphPath:@"me/photos"
                          andParams:params
                      andHttpMethod:@"POST"
                        andDelegate:self];

    [img release];

    [loadingIcon startAnimating];
}

As you can see I've placed the loadingIcon there to start animating when its uploading.. and at the request didload i did the stopanimating command when it has successfully uploaded.

-(void)request:(FBRequest *)request didLoad:(id)result{

    [loadingIcon stopAnimating];
    if ([result isKindOfClass:[NSArray class]]) {
        result = [result objectAtIndex:0];
    }
    if ([result objectForKey:@"owner"]) {
        [loadingIcon stopAnimating];

        UIAlertView *alert;

        alert = [[UIAlertView alloc] initWithTitle:@"" 
                                           message:@"Photo uploaded." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];

        [alert show];
        [alert release];
    } else {
       // [self.label setText:[result objectForKey:@"name"]];
    }
}

The thing is, the loading icon just keeps animating and no errors and all but still no picture uploaded to my facebook account. Any ideas why??

This are the codes in my.h file:

@interface UploadPhotosViewController: UIViewController(FBRequestDelegate, FBDialogDelegate, FBSessionDelegate){

 IBOutlet UIImageView *imageView; IBOutlet UIActivityIndicatorView *loadingIcon; IBOutlet UIBarButtonItem *_pushPick; IBOutlet UIBarButtonItem *_pushUpload; Facebook * _facebook; }

@property(readonly) Facebook *facebook;

  • (IBAction)pushUpload:(id)sender;
  • (IBAction)pushPick:(id)sender;

//UINavigationControllerDelegate, UIImagePickerControllerDelegate,

@end

Another thing to note is that there are no colors indicator for the (FBRequestDelegate, FBDialogDelegate, FBSessionDelegate) when there are supposed to be.. is it a problem?

I think it is because you're not declaring your protocols correctly. They go in angle brackets, not in parenthesis.

@interface UploadPhotosViewController : UIViewController<FBRequestDelegate, FBDialogDelegate, FBSessionDelegate>

Check if you have written delegates of Facebook in your.h file. Also check this code It worked for me..

NSString *string=@"Images of me";
SBJSON *jsonWriter = [[SBJSON new] autorelease];
    NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"My name", @"name",
                                string, @"description", nil];
    NSString *attachmentStr = [jsonWriter stringWithObject:attachment];



    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"This is image",@"description",
                                   @"Share on Facebook",  @"user_message_prompt",
                                   //actionLinksStr, @"action_links",
                                   attachmentStr, @"attachment",    
                                  /*Your image here", @"picture",
                                   nil];

Try this code

Hope it helps....

Try me/feed instead of me/photos.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM