2013-07-23 87 views
0
@facebook_required_lazy(scope=['manage_pages', 'publish_stream', 'photo_upload']) 
def index(request): 
    if request.method == 'POST': 
     form = CPYPosterForm(request.POST) 

     if form.is_valid(): 
      fb = require_persistent_graph(request) 
      msg = form.cleaned_data['msg'] 
      pages = form.cleaned_data['pages'] 

      res = dict() 
      for p in pages: 
       try: 
        key = PAGE_CHOICES[p] 
       except KeyError: 
        key = p 
       res[key] = fb.set('{page_id}/feed'.format(page_id=p), message=msg) 

我試圖張貼到多頁的供稿。當我發佈簡單的文字時,沒有問題。但是,當我嘗試上傳照片甚至是鏈接時,該項目確實會發佈到Feed,但是它是「其他人最近發佈的帖子」部分,而不是頁面Feed本身。Facebook圖形API&django-facebook - 張貼鏈接和照片到頁面供稿

它發佈爲我而不是頁面。有什麼我需要做一些特別的事情,以鏈接和/或照片的形式在頁面提要(如頁面)中發佈項目?

回答

0

Facebook Graph API PHP SDK posting on page as page

找到它了。有一個不同的訪問令牌用於模擬頁面,以作爲頁面。你從/我/賬戶得到這些信息,並使用該標記作爲頁面發佈。 更新的工作代碼:

@facebook_required_lazy(scope=['manage_pages', 'publish_stream', 'photo_upload']) 
def index(request): 
    if request.method == 'POST': 
     form = CPYPosterForm(request.POST) 

     if form.is_valid(): 
      fb = require_persistent_graph(request) 
      msg = form.cleaned_data['msg'] 
      pages = form.cleaned_data['pages'] 

      me_accounts = fb.get('/me/accounts') 
      access_token = None 

      resp = dict() 
      for p in pages: 
       for d in me_accounts['data']: 
        if d['id'] == p: 
         access_token = d['access_token'] 
       try: 
        key = PAGE_CHOICES[p] 
       except KeyError: 
        key = p 

       openfb = OpenFacebook(access_token) 
       resp[key] = openfb.set('{page_id}/feed'.format(page_id=p), message=msg, link='http://www.espn.com') 
相關問題