2011-11-03 61 views
1

我正在使用Facebook图表API将图片和消息发布到Facebook。我从Raywenderlich教程中获得了帮助。在最近两周前它工作正常。但现在它给我造成了问题。我正在获取所有的Facebook个人资料信息。使用图表api发布图片到Facebook

UIImage *image = [UIImage imageNamed:@"no_image.png"]; 



      data = UIImagePNGRepresentation(image); 






     NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/photos"]; 

    NSString *message = [couponInfoDictionary objectForKey:@"offerTitle"]; 

    message = [message stringByAppendingString:@"\n"]; 

    NSString *offerSlogan = [couponInfoDictionary objectForKey:@"offerSlogan"]; 

    message = [message stringByAppendingString:[NSString stringWithFormat:@"%@",offerSlogan]]; 

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 

    [request setData:data forKey:@"file"]; 
    [request setPostValue:message forKey:@"message"]; 
    [request setPostValue:_accessToken forKey:@"access_token"]; 
    [request setDidFinishSelector:@selector(sendToPhotosFinished:)]; 
    [request setDidFailSelector:@selector(requestError:)]; 
    [request setDelegate:self]; 
    [request startAsynchronous]; 



- (void)sendToPhotosFinished:(ASIHTTPRequest *)request 
{ 
    // Use when fetching text data 
    NSString *responseString = [request responseString]; 

    NSLog(@"response string before photo id %@",responseString); 

    NSMutableDictionary *responseJSON = [responseString JSONValue]; 
    NSString *photoId = [responseJSON objectForKey:@"id"]; 
    NSLog(@"Photo id is: %@", photoId); 

    NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@?access_token=%@", photoId, [_accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

    NSLog(@"sendToPhotosFinished = %@",urlString); 

    NSURL *url = [NSURL URLWithString:urlString]; 
    ASIHTTPRequest *newRequest = [ASIHTTPRequest requestWithURL:url]; 
    [newRequest setDidFinishSelector:@selector(getFacebookPhotoFinished:)]; 

    [newRequest setDelegate:self]; 
    [newRequest startAsynchronous]; 

} 

但是,当我张贴的形象,它给了我错误

{"error":{"message":"Error validating application.","type":"OAuthException"}} 

Photo id is: (null) 
sendToPhotosFinished = https://graph.facebook.com/(null)?access_token=ABACesEZBKr3gBALqa4yE2QAnJbNbGvQKa9iCm53GmTwHQYoyaxqAqmdLj0gw9uWCbyhP5sV7N6uZBjaFDpD6v6G1C7GcZCjvcZBPqt7b1ZAxKtDvepN8c&expires_in=4778 


Got Facebook Photo: {"error":{"message":"(#803) Some of the aliases you requested do not exist: (null)","type":"OAuthException"}} 

我已经花了我三天时间解决它。但仍然没有任何想法..如何解决这个问题?

回答

1

使用这种@ “117795728310 /照片” insted的我/照片

在你上面的代码中的第三行,

+0

不,它不工作..我已通过我的身份证。 –

+0

只是使用117795728310来表示“我”会起作用, –

0

照片的身份证件是:(空) 2012-02-16 11:59 :11.298 FBFun [2330:207]实得到照片:

{ 
    "error": { 
     "message": "(#803) Some of the aliases you requested do not exist: (null)", 
     "type": "OAuthException", 
     "code": 803 
    } 
} 

我用下面的代码,它是工作...

NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/USER_FACEBOOK_PROFILE_ID/photos"]; 
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"img1" ofType:@"jpg"]; 
nsstring *accessToken = @"AAACWZA..............................................Ts28iSOhGoOhe9qAgpZCL7AZDZD"; 
[request addData:[[NSUserDefaults standardUserDefaults]dataForKey:@"image1"] forKey:@"file"]; 
[request setPostValue:@"Testing App For iPhone, please don't comment..." forKey:@"message"]; 
[request setPostValue:accessToken forKey:@"access_token"]; 

[request setDelegate:self]; 
[request startAsynchronous];