1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Facebook の Graph API で一つの投稿を得る

Posted at

GraphAPI で特定の投稿を得る方法です。

curl を使う

get_single_post.sh
#
#	get_single_post.sh
#
#					Feb/19/2018
#
URL="https://graph.facebook.com/v2.12/"
ID_POST="341584679598802_396521764105093"
#
USER_TOKEN="FG4EFFBgb938BAO2ouOc1235pjXC8YgsXZBYRnZB8nNvwZCP7dJDTXq7pRrZCVXDX4rmH9hvEZCUj8ZA2ihBlMKMoVWWwzaaRzI8tqA6zCAhgZB12idZCYxIxXNmC112GypCJlnsGdUgLLwAYp0PAQinfL3J123f6or2JYj65bt0QSp1umNabcfg"
#
FIELDS='id,message,created_time'
#
curl "$URL$ID_POST?fields=$FIELDS&access_token=$USER_TOKEN"
#

python3 を使う

get_single_post.py
# ! /usr/bin/python
# -*- coding: utf-8 -*-
#
#	get_single_post.py
#
#						Feb/19/2018
#
# ----------------------------------------------------------------
import sys
import requests
# ----------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
access_token="FG4EFFBgb938BAO2ouOc1235pjXC8YgsXZBYRnZB8nNvwZCP7dJDTXq7pRrZCVXDX4rmH9hvEZCUj8ZA2ihBlMKMoVWWwzaaRzI8tqA6zCAhgZB12idZCYxIxXNmC112GypCJlnsGdUgLLwAYp0PAQinfL3J123f6or2JYj65bt0QSp1umNabcfg"
#
url= "https://graph.facebook.com/v2.12/"
id_post="341584679598802_396521764105093"
url_target=url + id_post
params={"access_token": access_token}
rr=requests.get(url_target,params=params)
print(rr.text)
#
sys.stderr.write("*** 終了 ***\n")
# ----------------------------------------------------------------

Node.js を使う

get_single_post.js
# ! /usr/bin/node
/*
	get_single_post.js

					Feb/19/2018
*/
// ----------------------------------------------------------------
console.error ("*** 開始 ***")
//
var Client = require('node-rest-client').Client
var client = new Client()

const url="https://graph.facebook.com/v2.12/"
const id_post="341584679598802_396521764105093"

const access_token="FG4EFFBgb938BAO2ouOc1235pjXC8YgsXZBYRnZB8nNvwZCP7dJDTXq7pRrZCVXDX4rmH9hvEZCUj8ZA2ihBlMKMoVWWwzaaRzI8tqA6zCAhgZB12idZCYxIxXNmC112GypCJlnsGdUgLLwAYp0PAQinfL3J123f6or2JYj65bt0QSp1umNabcfg"

url_target = url + id_post + "?access_token=" + access_token
//
client.get(url_target,function (data, response) {
	const json_str = data.toString('utf8')
	console.log (json_str)
	console.error ("*** 終了 ***")
})

// ----------------------------------------------------------------
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?