如何在我的 Facebook 墙上同时发布图像数据和网站 URL
Posted
技术标签:
【中文标题】如何在我的 Facebook 墙上同时发布图像数据和网站 URL【英文标题】:How Can I post Image data and website url together on my Facebook wall 【发布时间】:2012-12-14 08:13:34 【问题描述】:谁能解释我如何使用 FBGraph api 在我的 Facebook 墙上发布将显示网站图像和网址的图像数据?
谢谢,
【问题讨论】:
我试过了,params = [NSMutableDictionary dictionaryWithObjectsAndKeys: upperCaseStatusString, @"message",place_Name,@"name", CheckedFriendsNameStr, @"description", encoded_ImageData, @"picture", @"@987654321 @", @"链接", 无]; [appDelegate.m_Facebook requestWithGraphpath:@"me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self]; 通过使用这个,我可以发布图片但无法发布剩余的字段。 【参考方案1】:试试这个:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image_url,@"source",image_url, @"link",nil];
[facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
【讨论】:
你好 abi,我正在发布 NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:encoded_ImageData,@"source", @"itunes.apple.com/us/app/social-checkin/id504791401?mt=8", @"link",nil]; [appDelegate.m_Facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 但是我无法发布我的数据格式的图片,这里只有 iTunes 链接发布 @MeenakshiKatal 这里 ImageData 是一个 NSString 变量,保存要显示的图像的 url。【参考方案2】:大家好,现在我可以使用 social.framework 将图像数据和 url 一起发布。
请在您的项目中添加 social.framework 并使用 ios6 继续执行以下代码。
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
if (result == SLComposeViewControllerResultCancelled)
NSLog(@"ResultCancelled");
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"There might be some problem in facebook posting please try agian later." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
self.view.userInteractionEnabled = YES;
[loadingView removeFromSuperview];
else
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"We have checked in successfully on facebook." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
NSLog(@"Success");
self.view.userInteractionEnabled = YES;
[loadingView removeFromSuperview];
[controller dismissViewControllerAnimated:YES completion:Nil];
[self uploadMessageToTwitter];
;
controller.completionHandler =myBlock;
[controller addURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/social-checkin/id504791401?mt=8"]];
if (self.encoded_ImageData ==nil)
[controller addImage:[UIImage imageNamed:@"No_ImageFound.png"]];
else
[controller addImage:[UIImage imageWithData:self.encoded_ImageData]];
NSString *businessName;
//Set business name string to be passed on facebook
if (m_BusinessNameString == nil || [m_BusinessNameString isEqualToString:@""])
businessName = @"Business name not specified!";
else
businessName = [m_BusinessNameString uppercaseString];
NSString *nameString = [NSString stringWithFormat:@"CHECKED IN @"];
//user has checked in with his friends if sc-merchant
NSString *friendsString;
if ([checkedFriendsNameArray count] > 0)
NSMutableString *checkedFriendsTempStr = [[NSMutableString alloc] init];
for (NSMutableString *checkedStr in checkedFriendsNameArray)
[checkedFriendsTempStr appendString:[NSString stringWithFormat:@"%@,",checkedStr]];
friendsString = [NSString stringWithFormat:@"WITH %@",checkedFriendsTempStr];
else
friendsString = [NSString stringWithFormat:@"WITH NO FRIENDS"];
NSString *fname= [[NSUserDefaults standardUserDefaults] valueForKey:@"userfname"];
NSString *lname= [[NSUserDefaults standardUserDefaults] valueForKey:@"userlname"];
NSString *name=[fname stringByAppendingString:[NSString stringWithFormat:@"%@",lname]];
NSString *main_TextString =[NSString stringWithFormat:@"%@ \n %@ %@ %@ %@",upperCaseStatusString,name,nameString,businessName,friendsString];
[controller setInitialText:main_TextString];
[self presentViewController:controller animated:YES completion:Nil];
else
NSLog(@"UnAvailable");
self.view.userInteractionEnabled = YES;
[loadingView removeFromSuperview];
【讨论】:
【参考方案3】:尝试像这样通过 fbgraph 发送图片:
- (IBAction)buttonClicked:(id)sender
NSArray* permissions = [[NSArray alloc] initWithObjects:
@"publish_stream", nil];
[facebook authorize:permissions delegate:self];
[permissions release];
- (void)fbDidLogin
NSString *filePath =yourpathToImage;
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, yourpathToImage,
@"picture/jpeg", @"contentType",
@"Video Test Title", @"title",
@"Video Test Description", @"description",
nil];
[facebook requestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
【讨论】:
你好 Vishal,请解释一下我如何在上面的帖子中发布任何网址?通过使用它,我可以发布图片,但无法使用 :@"me/photos" 参数发布链接。我想将图片数据和 iTunes 链接一起发布。 @Meenakshi Katal 我也没有用这种方法发送 url 我也在搜索如果我成功了我也告诉你。以上是关于如何在我的 Facebook 墙上同时发布图像数据和网站 URL的主要内容,如果未能解决你的问题,请参考以下文章