我正在尝试使用 Facebook SDK 发布状态。一些用户已经使用 Facebook 登录。所以我有这个代码:
if (FBSession.activeSession.isOpen) {
NSLog(@"Already Open%@",[[FBSession activeSession] accessTokenData].accessToken);
// NSString *tok = [[FBSession activeSession] accessTokenData].accessToken;
NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions", nil];
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error) {
if(!error){
NSLog(@"Publish Permission Granted");
}
else
{
NSLog(@"Publish to get Read Permission");
} }];
//Remove indicator
[_activityView removeFromSuperview];
} else {
// OPEN Session!
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// if login fails for any reason, we alert
if (error) {
// show error to user.
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
// no error, so we proceed with requesting user details of current facebook session.
NSLog(@"----%@",[session accessTokenData].accessToken);
//NSString *tok = [session accessTokenData].accessToken;
NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions", nil];
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error) {
if(!error){
NSLog(@"Publish Permission Granted");
}
else
{
NSLog(@"Publish to get Read Permission");
} }];
[_activityView removeFromSuperview];
// [self promptUserWithAccountName]; // a custom method - see below:
}
}];
}
因此,让我们关注第一部分,即假设用户打开了会话(第二个只是打开一个新的会话,以防没有可用的会话)。授予发布权限后,我将如何发布带有 url 和图片的状态?Facebook 的例子根本没有帮助。我发现了一些其他的例子,但大多数都已经过时了。
我设法发布了一个简单的帖子:
FBRequest *postRequest = [FBRequest requestForPostStatusUpdate:@"hi" ];
[postRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// TODO: Check for success / failure here
}];
经过盛大的发布许可。我想要与 url 描述 imgurl 和标题类似的东西。