将UImage上传到facebook [英] Uploading UImage to facebook

查看:93
本文介绍了将UImage上传到facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将以下用于将UIImage发布到用户的Facebook墙的代码无效。我查看了与facebook sdk一起提供的示例代码及其工作正常。我无法找到我的代码出错的地方。

My following code for posting the UIImage to user's facebook wall is not working .I've looked into the sample code that comes along with the facebook sdk and its working fine. I am unable to find whats going wrong with my code.

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



} 

}

请告诉我可能出现的问题?

please tell me that what can be the problems?

提前感谢..

推荐答案

在调用委托方法 - (void)fbDidLogin 之后,需要调用upload函数。尝试这样做,它应该工作

you need to call the upload function after the delegate method - (void)fbDidLogin is being called .. try to do it like this and it should work

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

}

这篇关于将UImage上传到facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆