简体   繁体   English

我使用哪个Facebook登录按钮,为什么?

[英]Which Facebook login button do I use and why?

I have began developing a website which has facebook integration and it seems to work ok while using the Javascript SDK. 我已经开始开发一个具有Facebook集成的网站,并且在使用Javascript SDK时似乎可以正常工作。 I shown users name and profile pic fine. 我向用户显示了用户名和个人资料照片。 Then I read everywhere its best to use JS to make a auth connection and use the PHP SDK to run the API as its easier. 然后,我到处都读到了最好的方法,即使用JS建立身份验证连接,并使用PHP SDK来简化API的运行。

So I was faced with using one of two different login approaches, but for the life of me I cant just get what I want out of it. 因此,我不得不使用两种不同的登录方法之一,但是对于我一生来说,我无法从中获得想要的东西。 It really seems like the documentation doesnt clearly explain the pros/cons of anything they describe, and what situation is best for what approach. 看来,文档似乎并没有清楚地说明它们所描述的内容的优缺点,以及哪种情况最适合哪种方法。

For example: 例如:

    <?php if (!$user) { ?>
    <div class="fb-login-button" data-perms="email,user_birthday">Login with Facebook</div>
<?php } else { ?>

    Your user profile is
    <pre>
    <?php //print htmlspecialchars(print_r($user_profile, true)) ?>
    </pre>

    <?php echo $user_profile['name']; ?>

    <?php
    $data = array("message" => "Hello Woghfd!");
    $status = $facebook->api("/me/feed", "POST", $data); 
    //echo $user;

    ?>
<?php } 

But then there is also the other button: 但是,还有另一个按钮:

<fb:login-button scope="email,user_about_me">Connect Facebooks</fb:login-button>

And then the call to the JS function FB.login. 然后调用JS函数FB.login。

I wouldnt mind all of this but I am testing the ability to use PHP SDK to post to a users wall with this code: 我不会介意所有这些,但是我正在测试使用PHP SDK将此代码发布到用户墙上的功能:

$status = $facebook->api("/me/feed", "POST", $data);

And I keep getting an error message: 而且我不断收到错误消息:

Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action 致命错误:未捕获的OAuthException:(#200)用户未授权应用程序执行此操作

This is when I visit my website. 这是当我访问我的网站时。 Then when I log out, and log back in using my websites login button, it works. 然后,当我注销并使用我的网站登录按钮重新登录时,它可以工作。 I obviously dont want this to happen for every user that visits the site. 我显然不希望每个访问该网站的用户都发生这种情况。

Can someone please explain what all of these buttons mean? 有人可以解释所有这些按钮的含义吗? Ive spend a couple of days scouring the internet for explanations but things get confusing when the SDK updates are considered as I dont know what is the best approach anymore. 我花了几天时间在互联网上搜寻解释,但是当考虑更新SDK时,事情变得令人困惑,因为我不知道什么是最好的方法了。

Thanks. 谢谢。

The documentation states: 文档指出:

Facebook Platform supports two different OAuth 2.0 flows for user login: server-side (known as the authentication code flow in the specification) and client-side (known as the implicit flow). Facebook平台支持两种不同的OAuth 2.0用户登录流程:服务器端(在规范中称为身份验证代码流)和客户端(称为隐式流)。 The server-side flow is used whenever you need to call the Graph API from your web server. 每当您需要从Web服务器调用Graph API时,就会使用服务器端流程。 The client-side flow is used when you need to make calls to the Graph API from a client, such as JavaScript running in a Web browser or from a native mobile or desktop app. 当您需要从客户端(例如,在Web浏览器中运行的JavaScript或从本地移动或桌面应用程序中运行)调用Graph API时,将使用客户端流程。

Which makes it pretty clear: if you want to use the graph api from the server side then use the server side flow, if you want to make the api calls from the client side then use the client side flow. 这很清楚:如果要从服务器端使用图api,请使用服务器端流;如果要从客户端进行api调用,请使用客户端流。 You can of course use the server side flow for authentication and then interact with the graph api via the js sdk, or the other way around, but it just makes more sense to do it as they wrote. 当然,您可以使用服务器端流进行身份验证,然后通过js sdk或其他方式与graph api进行交互,但是这样做就像写它们那样更有意义。

The use of the login buttons means using the client side flow with the help of the js sdk. 登录按钮的使用意味着在js sdk的帮助下使用客户端流程。 The two different forms of buttons that you wrote are basically the same, as they say in the documentation : 您编写的按钮的两种不同形式基本相同,如文档中所述:

Using the new JavaScript SDK, the plugin is available via the <fb:login-button> XFBML tag or the <div class="fb-login-button"> HTML tag.

As for the error message you get when trying to post on the user wall, I don't see in your example that you are requesting for the publish_stream permission which is needed in order to post on the users wall. 至于尝试在用户墙上发布时收到的错误消息,在您的示例中我没有看到您正在请求publish_stream 权限 ,而该权限是发布在用户墙上所需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM