Google Chrome Extension + Login with Facebook + Parse

后端 未结 3 2166
再見小時候
再見小時候 2021-01-31 23:24

I\'m trying to build a google chrome extension, a use case requires that users can login with Facebook and share via a post to their Facebook wall.

The correct applicati

相关标签:
3条回答
  • 2021-01-31 23:42

    To answer your question (Don't have enough credit to comment).

    In your Facebook developer settings, click the advanced tab at the top, make sure "Client OAuth login" & "Embedded browser OAuth login" are both moved to "Yes" and then I had to add "http://www.facebook.com/" to the Valid OAuth redirect URI's

    0 讨论(0)
  • 2021-01-31 23:54

    I had this kind of problem lately ;). It's a bit complicated, but I'll try to explain it in the simplest way.

    Put somewhere in your extension (maybe options page) link "login with facebook" that redirects to: https://www.facebook.com/dialog/oauth?client_id=<APP_ID>&response_type=token&scope=<PERMISSIONS>&redirect_uri=http://www.facebook.com/connect/login_success.html

    When someone clicks on this link, will be asked to give permissions, etc (facebook page). If someone would agree, the page will load: http://www.facebook.com/connect/login_success.html with parameters access_token and expires_in in address.

    Now, background page should have script like this:

    var successURL = 'www.facebook.com/connect/login_success.html';
    
    function onFacebookLogin(){
      if (!localStorage.getItem('accessToken')) {
        chrome.tabs.query({}, function(tabs) { // get all tabs from every window
          for (var i = 0; i < tabs.length; i++) {
            if (tabs[i].url.indexOf(successURL) !== -1) {
              // below you get string like this: access_token=...&expires_in=...
              var params = tabs[i].url.split('#')[1];
    
              // in my extension I have used mootools method: parseQueryString. The following code is just an example ;)
              var accessToken = params.split('&')[0];
              accessToken = accessToken.split('=')[1];
    
              localStorage.setItem('accessToken', accessToken);
              chrome.tabs.remove(tabs[i].id);
            }
          }
        });
      }
    }
    
    chrome.tabs.onUpdated.addListener(onFacebookLogin);
    

    And this is how you get access token from facebook. Now you can send requests to https://graph.facebook.com.

    Hope I helped ;)

    0 讨论(0)
  • 2021-02-01 00:03

    now facebook has changed "Client Oauth Login" button location. You need to add a product and after adding facebook login you will found here

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