Pythontr

husonet | Tarih: 21.06.2011

facebook graph api kullanarak duvara yazma

Selaymun Aleykum,

Adımlar

  • Yeni bir uygulama oluşturulmalı. https://www.facebook.com/developers/createapp.php
  • Token oluşturulmalı https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=~APPID~&redirect_uri=~URL~&scope=publish_stream,offline_access,manage_pages
  • Oluşturulan token sayfalar için kullanılmalı https://graph.facebook.com/me/accounts?access_token=~TOKEN~



{
"name": "Pythontr.Com",
"category": "Websites",
"id": "1111111111",
"access_token": "kullanılacak token"
},


Facebook graph api için kullanım adresi
https://github.com/facebook/python-sdk

indirmek için
wget https://download.github.com/facebook-python-sdk-ad63a58.tar.gz


Sıkıştırılmış Dosyayı açalım
tar xzfv facebook-python-sdk-ad63a58.tar.gz


açılan paketin klasörüne gidelim
 cd facebook-python-sdk-ad63a58


paketi kuralım
python setup.py install


Kullanım

#!/usr/bin/python
#-*- coding:utf-8 -*-

import urllib
import pycurl
import StringIO
import sys
import facebook

TOKEN = "**************"
ADRES = "https://graph.facebook.com"
API = "******************"
API_USER = "***************"
ISLEM = "/feed"

#------------------------------------------------------------------------------
# duvar a gonder
def gonder(sName, sLink, sCaption, sDescription, sPicture, sMesaj, sToken):
graph = facebook.GraphAPI(sToken)
content= sMesaj
params = {
"name" : sName,
"link" : sLink,
"caption" : sCaption,
"description": sDescription,
"picture" : sPicture
}
response = graph.put_wall_post(message=content, attachment=params, profile_id=API)
print response