Facebook的API:如何张贴到我自己的墙页面? [英] Facebook API: How to post to my own wall page?

查看:192
本文介绍了Facebook的API:如何张贴到我自己的墙页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,也许有很多问题我也一样。但我不能解决如何在我的案件处理。
让启动:

我开发一个楼盘,网站的。流程图是简单的。用户可以根据自己想使用Facebook登录张贴许多。

现在他们都还好。我还可以解决有关如何每当用户完成他们的发布,它会自动发布到自己的个人/用户的墙壁上。

不过,我想,每一个上市也应贴我的财产信息页面上。是否会发布为用户谁使张贴或页面名称,没有问题。但我需要确保它不使用网页中我的个人/用户/管理员。

所以我找不到任何答案如何解决这个问题。在一个单一的网站会如何,我的脚本可以张贴到用户墙上谁做的张贴,也张贴到我的网页。如果禁止用户谁是外国人,而不是管理员发布到我的网页,那么如何让后到我的网页页面本身的名义下,当创建Facebook的API是属于用户。我需要创建不同的Facebook API对象?需要help..thank你的人谁可以帮助我。真的AP preciated。

下面是code我使用:

  $ =连接阵列(
                '消息'= GT; FB_STREAM_MSG,
                '图片'=> $ imgsrc,
                '链接'=> $ seourl,
                '名'=> $ prop_name,
                '标题'=> FB_STREAM_CAP,
                '描述'=> SUBSTR($ prop_desc,0150)。 '..',
            );
            $ facebook-> API(/ $ USER /饲料,POST,$附件);
            //$facebook->api(\"/\".FB_PAGE_ID,POST,$附件); //这是行不通的。


解决方案

好吧......所有的问题迎刃而解!

张贴到其他用户的墙,用户需要登录到生成用户令牌,code作为通常是这样的:

  $ =连接阵列(
'消息'= GT; ClearText_FB($ prop_name)
'图片'=> $ imgsrc,
'链接'=> $ seourl,
'名'=> ClearText_FB($ prop_name)
'标题'=> FB_STREAM_CAP,
'描述'=> ClearText_FB(SUBSTR($ prop_desc,0150)。'..'),
);
$ facebook-> API(/ $ USER /饲料,POST,$附件);

和张贴到自己的页面上墙,它无关紧要谁是用户,用户是否是页面的管理员与否。但它很重要,以获得页面访问令牌授予应用程序发布到网页墙。 FB的文档称,页面访问令牌将永远持续下去,所以我们只需要得到一次并妥善保管以备下次使用。

要获得页面访问令牌的第一次:

  $ page_access_token =;
            $结果= $ facebook-> API(/ ME /账户);
            的foreach($结果[数据]为$页){
                如果($页[身份证] == $ PAGE_ID){
                    // $ page_access_token = $页[ACCESS_TOKEN];
                    $ page_access_token = $ facebook-> API(/FB_PAGE_ID栏=的access_token?);
                    打破;
                }
            }

然后保存$ page_access_token值服务器/数据库或文件。 code以上的犯规需要了。注释掉或只是将其删除。删除名称字段,因为它似乎将放置后在其他用户的后期部分。这将张贴到网页壁页而不是用户:

  $ =连接阵列(
'消息'= GT; ClearText_FB($ prop_name)
'图片'=> $ imgsrc,
'链接'=> $ seourl,
'描述'=> ClearText_FB(SUBSTR($ prop_desc,0150)。'..'),
ACCESS_TOKEN'=> $ page_access_token,
);
$ facebook-> API(/FB_PAGE_ID'/饲料,POST,$附件);

Okay, there maybe many question same to me. But I can not solve how to handle in my case. Let start:

I develop a property listing website. The flowchart is simple. User can posting as many as they want using facebook login.

Now they all are okay. I also can solve about how whenever user finish their posting, it will automatically post to their personal/user wall page.

But I want that every listing should be also posted on MY property listing page. Whether it will post as user who make the posting or as page name, no problem. But I need to make sure it not use my personal/user/admin of the page.

So I can't find any answer how to solve this. How in a single website session, my script can post to the user wall who make the posting, and also post to my page. If it prohibited for user who are a foreigner and not the admin to post to my page, then how to make post to my page under the name of the page itself, when the facebook api created is belong to the user. Do I need to create different facebook api object? Need help..thank you for anyone who can help me. Really appreciated.

Below is the code I have use:

$attachment = array(
                'message' => FB_STREAM_MSG,
                'picture' => $imgsrc,
                'link' => $seourl,
                'name' => $prop_name,
                'caption' => FB_STREAM_CAP,
                'description' => substr($prop_desc,0,150) . '..',
            );
            $facebook->api("/$user/feed", 'POST', $attachment);
            //$facebook->api("/".FB_PAGE_ID, 'POST', $attachment); //this doesn't work.

解决方案

Ok...problem all SOLVED!

To POST to other user wall, the user need to sign in to generate user token and code as usually like this:

$attachment = array(
'message' => ClearText_FB($prop_name),
'picture' => $imgsrc,
'link' => $seourl,
'name' => ClearText_FB($prop_name),
'caption' => FB_STREAM_CAP,
'description' => ClearText_FB(substr($prop_desc,0,150) . '..'),
);
$facebook->api("/$user/feed", 'POST', $attachment);

And to post to our own page wall, it doesn't matter who is the user, whether the user is the admin or not of the page. But it matters to get the page access token to grant the application to post to page wall. The fb docs said the page access token will last forever, so we just need to get once and save it for next use.

To get page access token for the first time:

$page_access_token = "";
            $result = $facebook->api("/me/accounts");
            foreach($result["data"] as $page) {
                if($page["id"] == $page_id) {
                    //$page_access_token = $page["access_token"];
                    $page_access_token = $facebook->api("/".FB_PAGE_ID."?fields=access_token");
                    break;
                }
            }

Then save the $page_access_token value to server/db or file. Code above doesnt need anymore. Comment out or just remove it. Remove 'name' field as it seems will place post under other user post section. This will post to page wall as page not as user:

$attachment = array(
'message' => ClearText_FB($prop_name),
'picture' => $imgsrc,
'link' => $seourl,
'description' => ClearText_FB(substr($prop_desc,0,150) . '..'),
'access_token' => $page_access_token,
);
$facebook->api("/".FB_PAGE_ID.'/feed', 'POST', $attachment);

这篇关于Facebook的API:如何张贴到我自己的墙页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆