How to use AccessToken received from Snapchat to fetch UserData?

半世苍凉 提交于 2019-12-11 17:14:00

问题


Following snapkit Login Documentation (WEB), I implemented server side code and am able to obtain Access Token for the user (Section 2.5 at https://docs.snapchat.com/docs/tutorials/login-kit/web/ ).

How do I use this token to actually get user data? There is no mention of what one must do for ex. make a POST / GET request with the Access Token? This I think is the most critical part of the process, and it seems to be missing from the documentation.

I also tried using SCSDKLoginClient.getAccessToken(), I am able to retrieve token from Snapchat for the user who has logged in. However, I can't find any documentation on how to get user data there either. The only mention is that of a callback fetchUserData() but there's no field for Token there either.


回答1:


Answering my own question as I found the answer after long research, thanks to Snapchat Support.

Once you get the Access token by following documentation, follow below steps to get user info.

(Swap out ACCESS_TOKEN for your own access token.)

Make a POST request to

URL: "https://kit.snapchat.com/v1/me"
Headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + access_token}
jSON_body= {"query":"{me{displayName bitmoji{avatar} externalId}}"}

This should return jSON result like the following with the user information:

{
    "data": {
        "me": {
            "displayName": "DISPLAY_NAME",
            "bitmoji": {
                "avatar": "URL_BITMOJI_IMAGE"
            },
            "externalId": "EXTERNAL_ID"
        }
    },
    "errors": []
}


来源:https://stackoverflow.com/questions/57664956/how-to-use-accesstoken-received-from-snapchat-to-fetch-userdata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!