Can my extension get a user's e-mail address from Google Chrome?

后端 未结 2 473
夕颜
夕颜 2021-02-03 16:46

I\'ve got an extension for which some users contribute money or effort. I\'d like to be able to identify those users by their e-mail addresses, so I can display a \"Thank You!\"

2条回答
  •  孤独总比滥情好
    2021-02-03 16:52

    Allright, Got her solved. This website basically describes it:

    http://smus.com/oauth2-chrome-extensions/

    But not all of it is explained there. So:

    First of all you need an API Client ID and Client Secret so that you can be authorized by the user to use their details. The following steps will set that up in a fashion that will work with a chrome extension:

    1. Google API Console
    2. Create an API
    3. Go to API Access
    4. Create A Client ID
    5. Give it a name and a Logo, This name and logo will be displayed when the user is asked for permission for your application to retrieve their details. Next
    6. Select Web Application
    7. Click More to get URI and authorized javascript origins
    8. Set the Redirect URI to http://www.google.com/robots.txt
    9. Delete the javascript origins field so that there is none
    10. Click OK or whatever it is, copy the client ID and client secret out for later.

    Second you'll need the oauth2 javascript library, which is available here: https://github.com/borismus/oauth2-extensions/tree/master/lib

    You'll need to put that in a folder called oauth2 in the same directory as your html file.

    In you html file add the following stuff:

    
    
    

    In your manifest.json you need:

    "permissions": ["https://accounts.google.com/o/oauth2/token", "https://www.googleapis.com/oauth2/v1/userinfo"]

    Also in the manifest file you will need:

    "content_scripts": [   {
        "matches": ["http://www.google.com/robots.txt*"],
        "js": ["oauth2/oauth2_inject.js"],
        "run_at": "document_start"   }
    

    That should pretty much take care of it.

提交回复
热议问题