use*_*300 5 facebook objective-c ios facebook-ios-sdk
如何使用新的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];
}];
}
Run Code Online (Sandbox Code Playgroud)
vis*_*shy 12
你的代码很好,需要做一些细微的改动:
将图像以NSData格式添加到字典中,例如
[params setObject:UIImagePNGRepresentation(_image) forKey:@"picture"];
Run Code Online (Sandbox Code Playgroud)
并将图形路径更改为"me/photos"而不是"me/feed"
做出这些改变,它对我有用.请记住,您需要使用"publish_actions"权限.
| 归档时间: |
|
| 查看次数: |
8615 次 |
| 最近记录: |