我已成功使用SLRequest发布到Facebook,方法如下:
- (void)postScoreWithFBAccount:(ACAccount *)facebookAccount
{
NSString *messageToPost = [self.myString stringByAppendingString:@"https://www.example.com"];
NSDictionary *fbParameters = @{@"message": messageToPost};
NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
SLRequest *updateFeedRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedURL parameters:fbParameters];
updateFeedRequest.account = facebookAccount;
[updateFeedRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (responseData )
{
NSLog(@"Received Response: %@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300)
{
}
else
{
NSLog(@"HTTP %d Returned", urlResponse.statusCode);
}
}
else
{
[self showErrorAlertWithMessage:@"Unknown error occured, try again later!"];
}
}];
}
我以为我可以通过在我的消息字符串中附加一个url来附加一个url。问题是即使它被识别为Facebook上的链接,它也不会像在其他网址上那样在Facebook上显示时进行预览。有谁知道我如何附加一个类似于SLComposerViewController如何做到的URL,而是通过SLRequest?
答案 0 :(得分:2)
您可以向/feed
添加其他参数: link
。
有关完整的参数列表,请参阅here。
修改强>
您还可以在og:tags
内的网址中添加一些<head>
,Facebook会抓取并默认显示在Feed中:
<meta property="og:title" content="{your title here}" />
<meta property="og:description" content="{your description here}" />
<meta property="og:image" content="{your image here}" />
您可以在此处查看从您的网站抓取的Facebook内容:Debugger