if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound)
{
// No permissions found in session, ask for it
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error)
{
// If permissions granted, publish the story
if (!error)
{
[self postImageToFB] ;
}
}];
}
// If permissions present, publish the story
else
{
[self postImageToFB] ;
}
- (void) postImageToFB
{
NSData* imageData = UIImageJPEGRepresentation(self.image, 90);
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"test", @"message",
imageData, @"source",
nil];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos",friendName]
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(@"%@",error) ;
if(error == NULL)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:@"Post sucessed!!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] ;
[alert show] ;
}
}];
}
我可以使用- (void) postImageToFB
功能張貼在我自己的牆上當我改變[NSString stringWithFormat:@"%@/photos",friendName]
到@"me/photos"
iPhone - 如何張貼在朋友的Facebook牆上
但我不可以對我的朋友的牆上,也許許可圖像是錯的還是有一些問題我不知道?
我得到了這些錯誤
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xc0a7320 {com.facebook.sdk:ErrorInnerErrorKey=Error
Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xc001ea0 {NSUnderlyingError=0xaa45270 "bad URL", NSLocalizedDescription=bad URL}, com.facebook.sdk:HTTPStatusCode=200}