Facebook Graph API& django-facebook - 将链接和照片发布到页面供稿

时间:2013-07-23 18:50:29

标签: django facebook-graph-api django-facebook

@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中,但它会发布到“其他人最近的帖子”中。部分而不是页面提要本身。

它作为我发布而不是作为页面发布。我需要做一些特别的事情来在页面提要(作为页面)中发布带有链接和/或照片的项目吗?

1 个答案:

答案 0 :(得分:0)

Facebook Graph API PHP SDK posting on page as page

找到它。有一个不同的访问令牌可用于模拟页面以将发布为页面。你可以从/ me / accounts获得,并使用该令牌作为页面发布。 更新了工作代码:

@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')