2011-08-12 181 views
0

我已经通过网络搜索了所有,并下载了Facebook SDK的东西来尝试上传照片功能,它在那里工作。 完全相同的代码到我的应用程序,它不起作用。 请帮忙? 这是我的代码:Facebook图形API上传照片问题

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

正如你可以看到我已经放在那里loadingIcon启动动画时,其上载..,并在请求didload我做的stopanimating命令时,它已经成功上传。

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

事情是,加载图标只是保持动画,没有错误,但仍然没有图片上传到我的Facebook帐户。任何想法为什么?

这是我的.h文件中的代码:

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

IBOutlet UIImageView *imageView; 
IBOutlet UIActivityIndicatorView *loadingIcon; 
IBOutlet UIBarButtonItem *_pushPick; 
IBOutlet UIBarButtonItem *_pushUpload; 

Facebook * _facebook; } 

@属性(只读)Facebook的Facebook的* ;

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

// UINavigationControllerDelegate,UIImagePickerControllerDelegate,

@end

另外一点需要注意的是,目前的(FBRequestDelegate,FBDialogDelegate,FBSessionDelegate)无颜色指示灯,当有应该是.. 这是个问题吗?

回答

1

检查您是否在您的.h文件中编写了Facebook代表。 还要检查该代码 它的工作对我来说..

NSString *[email protected]"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]; 

试试这个代码

希望它可以帮助....

+0

嗨,感谢您的回复,但不幸的是,它仍然不适用于您的代码...>< – user891526

1

我试试/供稿代替我/照片。

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

我想这是因为你没有正确地宣布相关的协议。他们使用尖括号,而不是括号。

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