久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Facebook Graph API PHP SDK v4 - 在頁(yè)面上發(fā)布

Facebook Graph API PHP SDK v4 - Post on Page(Facebook Graph API PHP SDK v4 - 在頁(yè)面上發(fā)布)
本文介紹了Facebook Graph API PHP SDK v4 - 在頁(yè)面上發(fā)布的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我想讓我所有的網(wǎng)站作者有機(jī)會(huì)在我們的 facebook 頁(yè)面上發(fā)布他們的文章,而無(wú)需授予他們管理員訪問(wèn)權(quán)限.

I wanna give all my website authors a possiblity to post their articles on our facebook page without having go give them admin access to it.

所以我創(chuàng)建了一個(gè)簡(jiǎn)單的表單,作者在其中輸入:URL、圖像的 URL、消息

So i created a simple form, where the author types in: URL, URL to image, message

提交時(shí),此表單將向 facebook.php 發(fā)送一個(gè) ajax 請(qǐng)求,其中應(yīng)該"發(fā)生魔法.

On submit, this form will send a ajax request to facebook.php where the magic "should" happen.

第一個(gè)問(wèn)題發(fā)生在require_once".不可能在沒(méi)有錯(cuò)誤的情況下要求所有 4 個(gè)文件.如果我擺脫了 facebook 異常,那么除了請(qǐng)求本身之外,一切都正常.似乎有一個(gè) PHP 錯(cuò)誤,因?yàn)槲腋緵](méi)有收到 ajax 響應(yīng).

The first problem occurs at "require_once". It's not possible to require all 4 files without having an error. If i get rid of the facebook exception, then everything works except the request itself. There seems to be an PHP Error, because i get no ajax response at all.

session_start();

require_once($_SERVER['DOCUMENT_ROOT'].'/sys/facebook/FacebookSession.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/sys/facebook/FacebookRequest.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/sys/facebook/GraphObject.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/sys/facebook/FacebookRequestException.php');

use FacebookFacebookSession;
use FacebookFacebookRequest;
use FacebookGraphObject;
use FacebookFacebookRequestException;

$message = safe($_POST["message"]);
$url = safe($_POST["url"]);
$image = safe($_POST["image"]);

if($message == "" OR $url == "" OR $image == ""){
    echo "incomplete";
    return;
}

FacebookSession::setDefaultApplication('{APP ID}','{APP SECRET}');
$session = new FacebookSession('{Page Access Token}');

if($session) {
    try {
        $response = (new FacebookRequest(
            $session, 'POST', '/{Page ID}/feed', array(
                'message'       => $message,
                'link'          => $url,
                'picture'       => $image
            )
        ))->execute()->getGraphObject();
        echo "Posted with id: " . $response->getProperty('id');
    } catch(FacebookRequestException $e) {
        echo "Exception occured, code: " . $e->getCode();
        echo " with message: " . $e->getMessage();
    }
} else {
    echo "No Session available!";
}

推薦答案

更新: 2014 年 6 月 27 日,SDK 現(xiàn)在帶有 內(nèi)置自動(dòng)加載器,適用于無(wú)法使用 composer 的用戶(hù).

Update: June, 27 2014, The SDK now comes with a built-in autoloader for those who can't use composer.

require __DIR__ . '/path/to/facebook-php-sdk-v4/autoload.php';

如果這沒(méi)有自動(dòng)為您找到路徑,您可以使用 FACEBOOK_SDK_V4_SRC_DIR 定義它.

If that doesn't automatically find the path for you, you can define it with FACEBOOK_SDK_V4_SRC_DIR.

define('FACEBOOK_SDK_V4_SRC_DIR', '/path/to/facebook-php-sdk-v4/src/Facebook/');
require __DIR__ . '/path/to/facebook-php-sdk-v4/autoload.php';

<小時(shí)>

SDK 的內(nèi)部結(jié)構(gòu)依賴(lài)于您未包括的其他幾個(gè)類(lèi).這就是自動(dòng)加載在這里非常重要的原因.


The internals of the SDK rely on several other classes that you're not including. That's why autoloading is really important here.

最好的方法是安裝composer.并將 composer.json 文件中的 SDK 添加到項(xiàng)目的根目錄.

The best way to do this is to install composer. And add the SDK in a composer.json file to the root of your project.

{
    "require" : {
        "facebook/php-sdk-v4" : "4.0.*"
    }
}

然后從 composer.json 文件所在的命令行運(yùn)行 composer install.然后在腳本頂部包含自動(dòng)加載器.

Then run composer install from the command line where the composer.json file is. Then include the autoloader at the top of your script.

require_once __DIR__ . '/vendor/autoload.php';

手動(dòng)自動(dòng)加載

自動(dòng)加載這些文件的另一種方法是使用 require_once>rm-vanda:

Manual Autoloading

An alternative way to autoload these files is to replace your require_once's at the top with this solution from rm-vanda:

function facebookLoader($class) {
    require "/path/to/facebook-php-sdk-v4-master/src/" . str_replace("\", "/", $class) . ".php";
}

spl_autoload_register("facebookLoader");

這篇關(guān)于Facebook Graph API PHP SDK v4 - 在頁(yè)面上發(fā)布的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動(dòng)填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱(chēng) ASC)
主站蜘蛛池模板: 久草视频2 | 中文字幕一区二区三区精彩视频 | 国产9999精品 | 久久精品国产一区二区三区 | 久草新在线 | 一级片免费视频 | 成人欧美一区二区三区黑人孕妇 | 日韩人体在线 | 欧美1页| 中文字幕乱码视频32 | 精品国产视频 | 久久久久久久久久久久久久国产 | 精品久久久久久久久久久久久久 | 国产欧美一区二区久久性色99 | 日韩在线不卡视频 | 久久精品一区 | 午夜tv免费观看 | 美女福利网站 | 免费观看一级毛片 | 夜久久 | 日韩国产中文字幕 | 91青娱乐在线 | 精品国产一区二区三区久久久蜜月 | 91色在线 | 亚洲美女天堂网 | 亚洲伊人精品酒店 | 久久久久一区 | 亚洲精品高清视频在线观看 | 亚洲精品一区中文字幕 | 91精品国产综合久久久久蜜臀 | 91精品久久久久 | 亚洲美女天堂网 | 亚洲国产精品日本 | 久久精品国产一区二区电影 | 在线看av网址 | 在线观看免费福利 | 无码一区二区三区视频 | 365夜爽爽欧美性午夜免费视频 | 激情五月综合 | 一区视频| 精品一区二区三区在线视频 |