gpt4 book ai didi

iphone - 上传 UImage 到 facebook

转载 作者:行者123 更新时间:2023-11-28 23:01:06 26 4
gpt4 key购买 nike

我将 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];



}

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

提前致谢..

最佳答案

您需要在调用委托(delegate)方法 - (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];

}

关于iphone - 上传 UImage 到 facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10024056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com