[英]How do I parse data returned from the Graph Api
我有一個PHP表單(index.php),它使用Facebook Graph API來創建一個事件。 表單用於捕獲用戶輸入,並將此數據POST回API以創建事件。 這與本教程中解釋的代碼相同: http : //www.masteringapi.com/tutorials/how-to-create-facebook-events-using-graph-api/49/
結果是,它返回剛剛創建的事件的ID。
<?php
$app_id = "APP_key";
$app_secret = "APP_secret";
$my_url = "URL";
$code = $_REQUEST["code"];
if(empty($code)) {
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=create_event";
echo("<script>top.location.href='" . $auth_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$access_token = file_get_contents($token_url);
$event_url = "https://graph.facebook.com/me/events?" . $access_token;
?>
<style>
label {float: left; width: 100px;}
input[type=text],textarea {width: 210px;}
</style>
</head>
<body>
<div id="inputForm">
<form enctype="multipart/form-data" action="<?php echo $event_url; ?>" method="post">
<p><label for="name">Event Name</label><input type="text" name="name" value="" /></p>
<p><label for="description">Event Description</label><textarea name="description"></textarea></p>
<p><label for="location">Location</label><input type="text" name="location" value="" /></p>
<p><label for="">Start Time</label><input type="text" name="start_time" value="<?php echo date('Y-m-d H:i:s'); ?>" /></p>
<p><label for="end_time">End Time</label><input type="text" name="end_time" value="<?php echo date('Y-m-d H:i:s', mktime(0, 0, 0, date("m") , date("d")+1, date("Y"))); ?>" /></p>
<p><label for="picture">Event Picture</label><input type="file" name="picture" /></p>
<p>
<label for="privacy_type">Privacy</label>
<input type="radio" name="privacy_type" value="OPEN" checked='checked'/>Open
<input type="radio" name="privacy_type" value="CLOSED" />Closed
<input type="radio" name="privacy_type" value="SECRET" />Secret
</p>
<p><input type="submit" value="Create Event" /></p>
</form>
</div>
<?php
這段代碼效果很好,但我正在嘗試修改此代碼,以便index.php將數據發布到$ event_url以創建事件,但會將您重定向到顯示消息的確認頁面,例如:
“活動已成功創建!點擊此處訪問您的活動”,點擊“此處”會將您的活動重定向到Facebook。
有關如何做到這一點的任何想法?
將$event_url
更改$event_url
您網站上的event_submitter.php
的網頁,並將access_token
添加為表單上的隱藏字段。
event_submitter
頁面應該獲取$_POST
數據,去掉access_token
(如果你使用了php SDK,你可以刪除這部分),重新格式化其余的$_POST
數據,通過cURL將其發送到Facebook API並檢查響應。
如果得到正確的響應,則可以從中生成所需的輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.