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)

我正在尝试发布到多个页面的提要。当我发布简单的文字时,没问题。但是,当我尝试上传照片甚至链接时,该项目确实会发布到提要中,但它会发布到“其他人最近发布的帖子”部分,而不是页面提要本身。

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

4

1 回答 1

0

Facebook Graph API PHP SDK 在页面上作为页面发布

找到了。有一个不同的访问令牌用于模拟要作为页面发布页面。您从 /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')
于 2013-07-23T21:02:06.963 回答