Skip to content

Instantly share code, notes, and snippets.

@jk195417
Last active August 9, 2017 02:44
Show Gist options
  • Save jk195417/706f1cfa5c18853b14bc141911ffd3b2 to your computer and use it in GitHub Desktop.
Save jk195417/706f1cfa5c18853b14bc141911ffd3b2 to your computer and use it in GitHub Desktop.

Facebook api note

Get photo from user's posts

  1. Get user's posts

https://graph.facebook.com/{user_id}?fields=posts{id,type,message,created_time,attachments}&access_token={access_token}

will return

{
  "posts": {
    "data": [
      {
        "id": {id},
        "type": {type},
        "message": {message},
        "created_time": {created_time},
        "attachments": {
          "data": [
            {
              "subattachments": {
                "data": [
                  {
                    "description": "#test",
                    "media": {
                      "image": {
                        "height": {photo_height},
                        "src": {photo_url},
                        "width": {photo_width}
                      }
                    },
                    "target": {
                      "id": {photo_id},
                      "url": {photo_fb_url}
                    },
                    "type": "photo",
                    "url": {photo_fb_url}
                  }
                ]
              },
              "target": {
                "id": {post_id},
                "url": {post_fb_url}
              },
              "title": {post_title},
              "type": "album",
              "url": {post_fb_url}
            }
          ]
        }
      },
      ...
    ],
    "paging": {
      "previous": {previous-url},
      "next": {next-url}
    }
  },
  "id": {user-id}
}

collection posts["data"][]["attachments"]["data"][]["subattachments"]["data"][]["media"]["image"]["src"]

download photos by src

Get photo_id from user's albums (Timeline Photos)

  1. Get user's albums

https://graph.facebook.com/me/albums?fields=name,id,updated_time&access_token={access_token}

will return

"data": [
    {
      "name": "Timeline Photos",
      "id": {album_id},
      "updated_time": {updated_time}
    },
    {
      "name": "Mobile Uploads",
      "id": {album_id},
      "updated_time": {updated_time}
    },
    ...
  ]
}

Find album_id where "name": "Timeline Photos"

  1. Get photos from album

https://graph.facebook.com/{album_id}?fields=photos{created_time,updated_time,name,id}&access_token={access_token}

will return

{
  "photos": {
    "data": [
      {
        "created_time": {created_time},
        "name": "#test",
        "id": {photo_id},
        "updated_time": {updated_time}
      },
      {
        "created_time": {created_time},
        "id": {photo_id},
        "updated_time": {updated_time}
      }
    ],
  },
  "id": {album_id}
}

collection photo_id

Get photo_url by photo_id

https://graph.facebook.com/{photo_id}/picture?access_token={access_token}

will return

{
  "data": {
    "is_silhouette": false,
    "url": "some-image-url"
  }
}

download it by url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment