i am using php sdk. here is my php code
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => '123456',
'secret' => '123456abcdef',
));
// Get User ID
$user = $facebook->getUser();
//echo "-----".$user;
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user = null;
}
//print_r($user_profile);
$token = $facebook->getAccessToken();
//echo $token;
// store token
if ($user_profile['id'] && $token) {
$useradd = mysql_query("insert into fbdata (id,name,token) values ('".$user_profile['id']."','".$user_profile['name']."','".$token."')");
if ($uyeekle)
echo "Data added";
}
}
if (!$user) {
$args['scope'] = 'offline_access,read_stream,publish_stream';
$loginUrl = $facebook->getLoginUrl($args); ?>
<a href="<?php echo $loginUrl ?>">Facebook Login</a>
<?php } ?>
facebook redirect to my website with code parameter, not access token. and it s not looking like access token format. there is no | char. But i will try to upload a video with this code it works.
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => '123456',
'secret' => '123456abcdef',
));
$facebook->setFileUploadSupport(true);
$url = "https://graph-video.facebook.com/me/videos?title=abc&开发者_StackOverflow;description=desc&access_token=ABAD........AZDZD";
$attachment = array(
'description' => 'desc',
'title' => 'abc'
);
$attachment["file"] = '@' . realpath("123.mp4");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
$data = curl_exec($ch);
echo $data;
this code returns video id. then i want to get video info from that addresss https://graph.facebook.com/123456?access_token=ABAD........AZDZD
but its always saying false. where is my mistake?
Redirecting with a code instead of an access token is expected behavior, confirmed by the Facebook Authentication docs. When using server-side auth (PHP SDK), Facebook will redirect to http://YOUR_URL?code=A_CODE_GENERATED_BY_SERVER. You then have to resolve this code into an access token yourself (which you can do just by calling $facebook->getAccessToken()
). And as you say, you can then use this access token (not the code from the redirect) to make API calls.
If you're using the Facebook PHP SDK, you should just use that to make those API calls. I'm not sure about the specifics for uploading videos, but it should look something like this:
$facebook = new Facebook(array(
'appId' => '123456',
'secret' => '123456abcdef',
'fileUpload' => true,
));
$attachment = array(
'description' => 'desc',
'title' => 'abc',
'file' => '@' . realpath("123.mp4");
);
$result = $facebook->api('/me/videos', 'POST', $attachment);
var_dump($result);
精彩评论