Chrome Extension: Facebook OAuth with manually retrieved access token?

前端 未结 1 488
一向
一向 2021-01-07 15:43

As stated in the Facebook Oauth Documentation, in order to use the Client Side Flow with a Desktop App, the special return_uri https://www.facebook.com/connect/login_s

相关标签:
1条回答
  • 2021-01-07 16:05

    Yes, you can use it for the normal events (i.e. someone clicked a like button) like so:

    <div id="fb-root"></div>
    <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js#xfbml=1" id="facebook-jssdk"></script>
    <script type="text/javascript">
        FB.Event.subscribe('edge.create',
            function(response) {
                console.log(response);
            }
        );
    </script>
    

    Unfortunately for regular API calls you can't use the Facebook JS SDK from within your extensions. You'll have to roll your own API wrapper for that.

    An easy way to see if the access token is valid, is to make a graph API call to /me?fields=id with the access token you have saved. That will be fast and you can use the response to see if the access token is still valid. Best practice for extensions is to request the permission offline_access.

    Also, I would recommend having the redirect URI be on a domain you own. That way if other extensions are doing the same, your scripts won't interfere. Accessing the token will be the same.

    0 讨论(0)
提交回复
热议问题