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"
但是我不能在我朋友的墙上发帖,可能是权限不对或者有一些我不知道的问题?
我收到了这些错误
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}