[英]Upload photo using new iOS Facebook SDK API (3.0)
如何使用新的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”權限。
“我/照片”是指照片實際上位於您的Facebook個人資料中的“照片”列表中。 “me / feed”只是時間軸上的一個帖子。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.