0

我将 UIImage 发布到用户的 facebook 墙上的以下代码无法正常工作。我查看了 facebook sdk 附带的示例代码,并且工作正常。我找不到我的代码出了什么问题。

-(void) shareOnFacebook
{
facebook = [[Facebook alloc] initWithAppId:@"MYAPPID" andDelegate:(id)self];

NSArray * neededPermissions = [[NSArray alloc] initWithObjects:@"offline_access",@"user_about_me", @"publish_stream", @"user_photos", nil] ;
[facebook authorize:neededPermissions ];

if (![facebook isSessionValid]) 
{





    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   img, @"picture",
                                   nil];
    [facebook requestWithGraphPath:@"me/photos"
                                    andParams:params
                                andHttpMethod:@"POST"
                                  andDelegate:(id)self];



} 

}

请告诉我可能是什么问题?

提前致谢..

4

2 回答 2

2

您需要在调用委托方法后调用上传函数- (void)fbDidLogin..尝试这样做,它应该可以工作

- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[fb accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[fb expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];

    [self uploadImageWithName:yourImageName];
}


- (void) uploadImageWithName : (NSString*)name
{
    NSString *img = [NSString stringWithFormat:@"%@.PNG",name];
    UIImage *uploadImage = [UIImage imageNamed:img];

    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   [fb accessToken], 
                                   @"access_token",nil];

    [params setObject:uploadImage forKey:@"source"];

    [fb requestWithGraphPath:@"me/photos"
                             andParams: params
                         andHttpMethod: @"POST"
                           andDelegate:self];

}
于 2012-04-05T07:48:55.940 回答
0

这没有意义,不是吗?您询问 facebook 对象会话是否有效,如果不是,则继续上传照片。我不知道其余代码是否正常,但至少尝试删除条件或将其更改为if ([facebook isSessionValid]),看看是否有帮助。

于 2012-04-05T07:12:51.137 回答