Force FACEBOOK GRAPH API to show profile url image instead download it

坚强是说给别人听的谎言 提交于 2020-12-15 05:01:24

问题


Working with Facebook API Graph 8.0, I get a JSON with

https://graph.facebook.com/v8.0/1234567890?fields=picture&redirect=false&access_token=my_secret_token

with the following content:

{
  "picture": {
    "data": {
      "height": 100,
      "is_silhouette": false,
      "url": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=1234&height=100&width=100&ext=1234&hash=abc",
      "width": 100
    }
  },
  "id": "1234567890"
}

but when I tried to do a

<img src="https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=1234&height=100&width=100&ext=1234&hash=abc">

doesn't work, and in a browser it downloads it and not showing.

How can I use the image and/or how can i retrieve the Facebook Profile URL in order to show it?

Thanks in advance


回答1:


if you just want to show your image there is a much easier way to show images than querying graph api with access token and then showing the image.

you can directly use it with <img> tag.

just add /picture to the end of api call like this

<img src="https://graph.facebook.com/1234567890/picture">

you can also request different sizes like

<img src="https://graph.facebook.com/1234567890/picture?width=360&height=900">

or a square thumbnail with

<img src="https://graph.facebook.com/1234567890/picture?type=square">

for more informations check here : Facebook graph api v8 User Picture Notice

Facebook has two kinds of UIDs one is the original UID each user is assigned when they join facebook.com and the other is App-Scope UID each user gets when they install a facebook app. your app would always retrive App-Scope UID when calling endpoints like /me. the way to get original UID is either by manually collecting them with different techniques or setting a web-scrapper to do so automatically.

facebook is deprecating accessing photos with /user_id/picture endpoint when user_id is original UID unless access_token is provided this should not bother anyone because all apps get the app Scope UID unless you are trying to debug your app and cant figure out why it's not working.



来源:https://stackoverflow.com/questions/64074325/force-facebook-graph-api-to-show-profile-url-image-instead-download-it

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