0

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?

4

3 回答 3

1

检查您是否在 .h 文件中写入了 Facebook 的代表。还要检查这个代码它对我有用..

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];

试试这个代码

希望能帮助到你....

于 2011-08-12T13:11:18.647 回答
1

我认为这是因为您没有正确声明您的协议。它们放在尖括号中,而不是括号中。

@interface UploadPhotosViewController : UIViewController<FBRequestDelegate, FBDialogDelegate, FBSessionDelegate>
于 2012-09-03T13:48:13.083 回答
1

试试我/喂而不是我/照片。

[_facebook requestWithGraphPath:@"me/feed"
                      andParams:params
                  andHttpMethod:@"POST"
                    andDelegate:self];
于 2011-09-13T08:19:20.973 回答