IOS:什么是本地的;用于iOS的Facebook登录SDK;?
我正在开发ios应用程序,其中我必须实现facebook发布/共享功能。我为分享所做的是 1:如果用户未登录,我将对此进行检查IOS:什么是本地的;用于iOS的Facebook登录SDK;?,ios,iphone,facebook,facebook-graph-api,Ios,Iphone,Facebook,Facebook Graph Api,我正在开发ios应用程序,其中我必须实现facebook发布/共享功能。我为分享所做的是 1:如果用户未登录,我将对此进行检查 if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded||FBSession.activeSession.state == FBSessionStateOpen) { //NSLog(@"Open"); //Set already opened session to FB
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded||FBSession.activeSession.state == FBSessionStateOpen) {
//NSLog(@"Open");
//Set already opened session to FBSession
[FBSession setActiveSession:appDelegate.session];
//if user logged in already, perform sharing on fb
[self sharePostOnFb];
}else{
//if user is not logged in
[self openFbLogin];
}
-(void)openFbLogin
{
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"email",@"publish_actions"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
// Retrieve the app delegate
//AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
// Call the app delegate's sessionStateChanged:state:error method to handle session state changes
//[appDelegate sessionStateChanged:session state:state error:error];
if (state == FBSessionStateOpen) {
NSLog(@"opened");
[self sharePostOnFb];
}
}];
}
-(void)sharePostOnFb
{
NSString *strBznsName = [[[Global sharedInstance]getBznsInfo] objectForKey:@"name"];
NSString *strUserReceive = [NSString stringWithFormat:@"%@ %@ received %@.",[[[Global sharedInstance]getUserData] objectForKey:@"firstname"],[[[Global sharedInstance]getUserData] objectForKey:@"lastname"],dataStampDeal.strDealTerms];
NSString *urlLogoBkString= @URL_BZNSImgPath;
NSURL *urlLogoBkImage = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",urlLogoBkString,[[[Global sharedInstance]getBznsInfo] objectForKey:@"logo" ]]];
NSString *StrUrl = [NSString stringWithFormat:@"%@",urlLogoBkImage];
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
strBznsName, @"name",
@"Powered By Anyloyalty", @"caption",
strUserReceive, @"description",
StrUrl, @"picture",
nil];
// Make the request
[FBRequestConnection startWithGraphPath:@"/me/feed"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Link posted successfully to Facebook
NSLog(@"result: %@", result);
strFbPostId = [result valueForKey:@"id"];
NSLog(@"post id: %@", strFbPostId);
//[self WebServiceHandler:NO];
//[appDelegate startanimation];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"%@", error.description );
NSDictionary *errorInformation = [[[[error userInfo] objectForKey:@"com.facebook.sdk:ParsedJSONResponseKey"]
objectForKey:@"body"]
objectForKey:@"error"];
//NSLog(@"%@", errorInformation );
//__block NSString *alertText = @"Your action will not be published to Facebook.";
__block NSString *alertText = [errorInformation valueForKey:@"message"];
[[[UIAlertView alloc] initWithTitle:@"error"
message:alertText
delegate:self
cancelButtonTitle:@"OK!"
otherButtonTitles:nil] show];
}
}];
}
facebook登录((无效)openFbLogin())
正在打开web对话框。成功登录后。我正在fb上共享post((void)sharePostOnFb())
,我收到错误消息
“(#200)用户尚未授权应用程序执行此操作”
对于发布/共享,我必须获得FB对“发布行动”权限的批准。我已经向FB应用程序开发中心提交了我的申请。我收到了这个信息
“您的应用程序不得使用Facebook Web对话框。使用我们的iOS版本机Facebook登录SDK,以便用户无需登录两次。”
现在我想问“什么是iOS版的原生Facebook登录SDK”?我该如何将其与我的应用程序集成?Facebook明确表示
所有iOS和Android应用程序都应使用其iOS和Android SDK请求权限。其他应用程序应尽可能使用JavaScript请求权限
iOS和Android上的本机应用程序尤其应该使用它们的SDK流,因为它们经过优化,可以在各种类型的设备上稳定运行,无需任何手动调整
特别是,他们的本地SDK允许已经登录Facebook应用程序的用户授予权限,而无需再次登录他们的Facebook帐户。这将导致比不使用我们的SDK和在本机应用程序中嵌入的web视图中呈现我们的登录对话框更好的转换,因为web视图最初不会有任何Facebook会话数据,并且需要用户登录到他们的Facebook帐户
请注意:如果您使用的是苹果的社交框架,您可以继续这样做,但请确保如果用户没有使用iOS集成,您的应用程序会返回到用于iOS的Facebook SDK。但是,这可能会产生超出必要的工作,因此我们强烈建议使用他们的SDK
以下是SDK实现的详细信息:本机Facebook登录只不过是使用iOS FB框架,并使用该框架创建登录。developers.facebook.com上明确提到了如何使用there框架登录。您还可以查看他们提供的用于登录的示例 实际上,它检查用户是否在设备中安装了Facebook应用程序,以及用户是否登录了Facebook应用程序。若用户已登录,则不会要求用户再次登录。如果用户没有登录,他们将被重定向到safari,在那里他们将不得不登录到FB 它很容易集成。解释得很好