问题
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