2

我正在尝试打开 Facebook 链接并使用以下代码将符合 iOS 上的 URL 协议。

NSString *url = [self.dataSource getFacebookURL];
url = [url stringByReplacingOccurrencesOfString:@"http://www.facebook.com/" withString:@"fb://profile/"];
NSLog(@"LINK: %@", url);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

但是当尝试加载个人资料或页面(即组织的)时,它总是将我带到最后打开的屏幕。有没有办法直接链接到页面和个人资料?我按照此处描述的说明进行操作,但没有成功。

我要链接的页面是“ https://www.facebook.com/junction11 ”,如果有帮助的话……

谢谢,马克斯

使固定

所以我找到了一个解决方案,首先加载组/人员/页面的图形值,解析它们,然后使用 Facebook-ID 创建一个新的 url。代码有效(不知道效果如何),看起来像这样:

// Look at graph page instead of www page
NSString *dataURL = [url stringByReplacingOccurrencesOfString:@"www" withString:@"graph"];
// Load data and parse using JSON parser
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:dataURL]];
NSError *error;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

if (!error) { NSLog(@"ERROR: %@", error); return; }

// If no error occurred, make new url and replace the username by the facebook-ID
url = [url stringByReplacingOccurrencesOfString:[dictionary objectForKey:@"username"] withString:[dictionary objectForKey:@"id"]];
// And voilà, it works :]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

谢谢谷歌和时间...

4

1 回答 1

1
NSURL *url = [NSURL URLWithString:@"fb://profile/<id>"];
[[UIApplication sharedApplication] openURL:url];

计划

fb://profile – Open Facebook app to the user’s profile

fb://friends – Open Facebook app to the friends list

fb://notifications – Open Facebook app to the notifications list (NOTE: there appears to be a bug with this URL. The Notifications page opens. However, it’s not possible to navigate to anywhere else in the Facebook app)

fb://feed – Open Facebook app to the News Feed

fb://events – Open Facebook app to the Events page

fb://requests – Open Facebook app to the Requests list

fb://notes – Open Facebook app to the Notes page

fb://albums – Open Facebook app to Photo Albums list
于 2012-12-29T19:39:43.420 回答