使用Python在Facebook粉丝页面上发布
我尝试了一些关于如何在Facebook墙上发布的代码。但我想做一点不同的事。我想在我的facebook粉丝页面上发表文章。下面的代码刚刚发布在我的个人资料上。有谁能给我一个在粉丝页面发布的线索吗使用Python在Facebook粉丝页面上发布,python,facebook,facebook-graph-api,Python,Facebook,Facebook Graph Api,我尝试了一些关于如何在Facebook墙上发布的代码。但我想做一点不同的事。我想在我的facebook粉丝页面上发表文章。下面的代码刚刚发布在我的个人资料上。有谁能给我一个在粉丝页面发布的线索吗 #!/usr/bin/python import facebook import urllib import urlparse FACEBOOK_APP_ID = 'X' FACEBOOK_APP_SECRET = 'Y' FACEBOOK_PROFILE_ID = 'MyProfileId (*
#!/usr/bin/python
import facebook
import urllib
import urlparse
FACEBOOK_APP_ID = 'X'
FACEBOOK_APP_SECRET = 'Y'
FACEBOOK_PROFILE_ID = 'MyProfileId (**not page id, right?**)'
oauth_args = dict(client_id = FACEBOOK_APP_ID,
client_secret = FACEBOOK_APP_SECRET,
grant_type = 'client_credentials')
oauth_response = urllib.urlopen('https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(oauth_args)).read()
page_token='PAGE TOKEN GOT INhttps://graph.facebook.com/SITE'
fields=access_token
attach = {
"name": 'Hello world',
"link": 'http://www.example.com',
"caption": 'test post',
"description": 'some test',
"picture" : 'http://www.example.com/picture.jpg',
"page_token" : page_token
}
try:
oauth_access_token = urlparse.parse_qs(str(oauth_response))['access_token'][0]
except KeyError:
raise
print oauth_access_token
facebook_graph = facebook.GraphAPI(oauth_access_token)
try:
response = facebook_graph.put_wall_post('', attachment=attach,profile_id = FACEBOOK_PROFILE_ID)
except facebook.GraphAPIError as e:
print e
我更正了代码,下面是解决方案:
#!/usr/bin/python
# coding: utf-8
import facebook
import urllib
import urlparse
access_token_page='X'
FACEBOOK_APP_ID = 'Y'
FACEBOOK_APP_SECRET = 'Z'
FACEBOOK_PROFILE_ID = 'W'
oauth_args = dict(client_id = FACEBOOK_APP_ID,
client_secret = FACEBOOK_APP_SECRET,
grant_type = 'client_credentials')
oauth_response = urllib.urlopen('https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(oauth_args)).read()
attach = {
"name": 'Hello world',
"link": 'http://www.example.com',
"caption": 'test post',
"description": 'some test',
"picture" : 'http://www.example.com/picture.jpg',
}
facebook_graph = facebook.GraphAPI(access_token_page)
try:
response = facebook_graph.put_wall_post('', attachment=attach)
except facebook.GraphAPIError as e:
print e
有关身份验证的信息,请访问:我更正了代码,以下是解决方案:
#!/usr/bin/python
# coding: utf-8
import facebook
import urllib
import urlparse
access_token_page='X'
FACEBOOK_APP_ID = 'Y'
FACEBOOK_APP_SECRET = 'Z'
FACEBOOK_PROFILE_ID = 'W'
oauth_args = dict(client_id = FACEBOOK_APP_ID,
client_secret = FACEBOOK_APP_SECRET,
grant_type = 'client_credentials')
oauth_response = urllib.urlopen('https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(oauth_args)).read()
attach = {
"name": 'Hello world',
"link": 'http://www.example.com',
"caption": 'test post',
"description": 'some test',
"picture" : 'http://www.example.com/picture.jpg',
}
facebook_graph = facebook.GraphAPI(access_token_page)
try:
response = facebook_graph.put_wall_post('', attachment=attach)
except facebook.GraphAPIError as e:
print e
有关身份验证的信息可以通过以下方式获取:获取页面访问令牌,并发布到页面的提要连接。都在FB文档里,看一看。我已经有了页面访问令牌,但我仍然有问题。首先我得到了“演员是页面的帖子不能同时包含目标id”,然后我从put_wall_post中删除了FACEBOOK_PROFILE_id,我得到了“主题必须是页面”。获得页面访问令牌,然后发布到页面的提要连接。都在FB文档里,看一看。我已经有了页面访问令牌,但我仍然有问题。首先我得到了“演员是一个页面的帖子不能同时包含一个目标id”,然后我从put_wall_帖子中删除了FACEBOOK_PROFILE_id,我得到了“主题必须是一个页面”。这实际上是发布到粉丝页面还是仅仅是一个特定用户的流?我看不到关于实际粉丝页面的任何细节。这实际上是发布到粉丝页面还是仅仅是特定用户的流?我没有看到任何关于实际风扇页面的详细信息。