FbConnect:同时在用户的墙上和新闻源中发布?
Posted
技术标签:
【中文标题】FbConnect:同时在用户的墙上和新闻源中发布?【英文标题】:FbConnect : Publish on user's wall and in the newsfeed simultaneously? 【发布时间】:2012-03-30 23:28:25 【问题描述】:我正在使用以下代码通过 FbConnect 登录到 Fb:
- (IBAction)loginButtonClicked:(id)sender
facebook = [[Facebook alloc] initWithAppId:@"355949667779777" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"])
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
if (![facebook isSessionValid])
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_likes",
@"read_stream",
@"publish_stream",
nil];
[facebook authorize:permissions];
[permissions release];
然后我使用以下代码发布到用户的墙上:
- (IBAction)postToWallPressed:(id)sender
SBJSON *jsonWriter = [[SBJSON new] autorelease];
// The action links to be shown with the post in the feed
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
@"Get Started",@"name",@"http://m.facebook.com/apps/hackbookios/",@"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
// Dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Testing VB", @"name",
@"Integrating Facebook in VB.", @"caption",
@"VB is a voice morphing app for videos.", @"description",
@"http://www.google.com/", @"link",
@"http://www.freeimagehosting.net/newuploads/49ncw.png", @"picture",
actionLinksStr, @"actions",
nil];
[facebook dialog:@"feed" andParams:params andDelegate:self];
帖子在用户的墙上正常发布,但没有在新闻源中发布。
我在这里做错了什么?
【问题讨论】:
【参考方案1】:新更新的 Facebook API 的链接: https://github.com/facebook/facebook-ios-sdk
您是否使用更新的 Facebook API?因为在最近更新的 facebook API 中,您根本不需要使用 JSONWriter
和 ActionLinks
。因此,请尝试升级您的 API 并按照 facebook 网站提供的 facebook 教程进行操作。
Facebook API 教程链接: https://developers.facebook.com/docs/mobile/ios/build/
您也可以试试这个代码。它对我来说非常有效。我正在使用 ARC(自动引用计数)。所以如果你想自己添加它。不要忘记在代码和.plist
文件中添加你APP_ID
-(void)buttonPressed:(id)sender
facebook = [[Facebook alloc] initWithAppId:@"YOUR_APP_ID" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"])
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
if (![facebook isSessionValid])
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_likes",
@"read_stream",
@"publish_stream",
nil];
[facebook authorize:permissions];
else
[self postWall];
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
return [facebook handleOpenURL:url];
- (void)fbDidLogin
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
[self postWall];
-(void)postWall
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"https://developers.facebook.com/docs/reference/dialogs/",@"link",
@"http://fbrell.com/f8.jpg",@"picture",
@"Facebook Dialogs",@"name",
@"Reference Documentation",@"caption",
@"Using Dialogs to interact with users.",@"description",
@"Facebook Dialogs are so easy!",@"message",
nil];
[[self facebook] dialog:@"feed" andParams:params andDelegate:self];
【讨论】:
我认为我们不能......但我们甚至可以尝试获取本地图像的 url 并使用该 url 代替那个。可能会起作用..检查后通知我..以上是关于FbConnect:同时在用户的墙上和新闻源中发布?的主要内容,如果未能解决你的问题,请参考以下文章
如何像 soundcloud 那样在新闻源中嵌入内联 iframe?