gpt4 book ai didi

objective-c - 使用新的 iOS Facebook SDK API (3.0) 上传照片

转载 作者:可可西里 更新时间:2023-11-01 04:19:11 25 4
gpt4 key购买 nike

如何使用新的 API/SDK 从 iOS 应用程序将照片上传到 Facebook?我已经尝试过了,但我一无所获,只是继续原地打转。这是我目前拥有的代码:

-(void)dataForFaceboo{
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
self.uploadPhoto.image, @"picture", nil];
}

-(void)uploadToFacebook{

[self dataForFacebook];

NSLog(@"Going to facebook: %@", self.postParams);

// Hide keyboard if showing when button clicked
if ([self.photoCaption isFirstResponder]) {
[self.photoCaption resignFirstResponder];
}
// Add user message parameter if user filled it in
if (![self.photoCaption.text
isEqualToString:kPlaceholderPostMessage] &&
![self.photoCaption.text isEqualToString:@""])
{
[self.postParams setObject:self.photoCaption.text forKey:@"message"];
}
[FBRequestConnection startWithGraphPath:@"me/feed"
parameters:self.postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error) {
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
} else {
alertText = [NSString stringWithFormat:
@"Posted action, id: %@",
[result objectForKey:@"id"]];
}
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:@"Result"
message:alertText
delegate:self
cancelButtonTitle:@"OK!"
otherButtonTitles:nil] show];
}];
}

最佳答案

您的代码很好,需要做一些小改动:

将图像以NSData格式添加到字典中,如

[params setObject:UIImagePNGRepresentation(_image) forKey:@"picture"];

并将图表路径更改为 "me/photos" 而不是 "me/feed"

进行这些更改,它对我有用。请记住,您需要使用"publish_actions" 权限。

关于objective-c - 使用新的 iOS Facebook SDK API (3.0) 上传照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11974972/

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