|
|
|
รวบกวนช่วยบอกโค้ดดึงข้อมูลจาก json decode ทีครับดึงไม่ถูกอ่ะครับ มือใหม่ครับ |
|
|
|
|
|
|
|
ช่วยบอกโค้ดดึงข้อมูลจาก json decode ฟร์อมนี้ที่ครับ ดึงไม่ถูกอ่ะครับ #มือใหม่ครับ
Code (PHP)
<?php
/*
* Created by Tharin Nilsri
*/
header("Content-type: text/html; charset=utf-8");
set_time_limit(0);
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
ini_set('display_errors', E_ALL ^ E_NOTICE ^ ~E_DEPRECATED);
class testfb{
function fb(){
session_start();
$callback='http://'.$_SERVER['SERVER_NAME'].'/testfb.php';
$appid='xxxxxxxxxxxxxxxx';
$appsecret='xxxxxxxxxxxxxxxxxx';
$code=trim($_GET['code']);
if($_GET['local_token']){
echo "<br>".__LINE__.':';
$post="access_token=".$_GET['local_token'];
$url = "https://graph.facebook.com/me?$post";
$response=json_decode(self::http($url,"GET",$post));
echo "<br>".__LINE__.':$response: <pre>'.var_export($response,true).'</pre>';
}elseif($_SESSION['api_fb_token']){
echo "<br>".__LINE__.':';
echo "<br>".__LINE__.':token:'.$_SESSION['api_fb_token'];
$post="access_token=".$_SESSION['api_fb_token'];
$url = "https://graph.facebook.com/me?$post";
$response=json_decode(self::http($url,"GET",$post));
echo "<br>".__LINE__.':$response: <pre>'.var_export($response,true).'</pre>';
}elseif(empty($code)){
echo "<br>".__LINE__.':';
$url='https://www.facebook.com/dialog/oauth?client_id='.$appid.'&redirect_uri='.$callback;
self::rd($url);
}elseif($code){
echo "<br>".__LINE__.':';
$url="https://graph.facebook.com/oauth/access_token";
$post="client_id=$appid&redirect_uri=".urlencode($callback)."&client_secret=$appsecret&code=$code";
echo "<br>".__LINE__.":URL : $url";
$response=self::http($url,'POST',$post);
parse_str($response,$params);
if($params['access_token']){
$_SESSION['api_fb_token']=$params['access_token'];
}
self::rd($callback);
echo "<br>".__LINE__.":\$params: ".var_export($params,true);
}else{
echo "<br>".__LINE__.':';
}
}
function rd($url){
echo '<meta http-equiv="refresh" content="5;URL='.$url.'">';
echo "<a href=\"$url\">Please wait or Click To Continue</a>";
}
function call($url,$data){
}
function http($url, $method, $postfields = NULL,$auth=null) {
$this->http_info = array();
$ci = curl_init();
/* Curl settings */
// CURLOPT_CONNECTTIMEOUT => 10,
// CURLOPT_RETURNTRANSFER => true,
// CURLOPT_TIMEOUT => 60,
// CURLOPT_USERAGENT => 'facebook-php-3.1',
curl_setopt($ci, CURLOPT_USERAGENT,'facebook-php-3.1');
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT,30);
curl_setopt($ci, CURLOPT_TIMEOUT,50);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ci, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
curl_setopt($ci, CURLOPT_HEADER, FALSE);
// echo "<br>\CURLAUTH_BASIC : ".CURLAUTH_BASIC ;
// echo "<br>\CURLAUTH_NTLM : ".CURLAUTH_NTLM ;
// if($auth)
// {
// Authorization: Basic
// curl_setopt($ci,CURLOPT_HTTPAUTH,'OAuth');
// curl_setopt($ci,CURLOPT_USERPWD,$auth);
// }
switch ($method) {
case 'POST':
curl_setopt($ci, CURLOPT_POST, TRUE);
if (!empty($postfields)) {
curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
}
break;
case 'DELETE':
curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
if (!empty($postfields)) {
$url = "{$url}?{$postfields}";
}
}
//echo "<br>\$url: $url";
curl_setopt($ci, CURLOPT_URL, $url);
$response = curl_exec($ci);
$this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
$this->http_info = array_merge($this->http_info, curl_getinfo($ci));
$this->url = $url;
// echo "<br>ERROR: ".curl_error($ci);
//echo "<br>ERROR: ".curl_errno($ci);
//echo "<br>\$this->http_code:". $this->http_code;
//echo "<br>\$this->http_info:".var_export($this->http_info,true);
// echo "<br>\$response: ".$response;
curl_close ($ci);
return $response;
}
/**
* Get the header info to store.
*/
function getHeader($ch, $header) {
$i = strpos($header, ':');
if (!empty($i)) {
$key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
$value = trim(substr($header, $i + 2));
$this->http_header[$key] = $value;
}
return strlen($header);
}
}
$fb=new testfb();
$fb->fb();
//$rs=$fb->http('https://graph.facebook.com/me','GET');
//echo "<br><pre>".var_export($rs,true).'</pre>';
//$rs=$fb->http('https://accounts.google.com','GET');
//echo "<br><pre>".var_export($rs,true).'</pre>';
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2013-10-31 15:05:20 |
By :
dagonov |
View :
1224 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองใช้พวก var_dump() ดูก่อนครับ
Decodes a JSON string
|
|
|
|
|
Date :
2013-11-01 11:00:22 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|