问题
I've been working at this for a few hours, but the poor documentation is of no help.
All I want to do is grab the data that exists at https://graph.facebook.com/cocacola/ as an example, and I cant even do that.
I'm using the latest php API from facebook.
This is my code, which returns nothing:
<?php
require '../src/facebook.php';
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => '254752073152',
'secret' => '904270b68a2cc3d54485323652da4d14',
'cookie' => true,
));
$coke = $facebook->api('/cocacola');
echo '<pre>';
print_r($coke);
echo '</pre>';
Any idea?
回答1:
Sorry I can't comment, but that doesn't look like a valid API key (not long enough). The 'appId'
should be your API key not your Application ID.
回答2:
Checkout the tutorial http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/ to fully understand step by step of graph api and php sdk.
回答3:
Have you checked out efpa, you can get a whole user's stream using(customizable with CSS);
$userHome = $myapp->userHome();
foreach($userHome as $uhf) {
$myapp->userStreamTmp($uhf);
}
or getting user information;
$myapp->userInfo('name');
// or
$myapp->userInfo('gender');
// or
$myapp->userInfo('id');
you can check out the documentation http://labs.gurron.com/projects.php?proj=efpa&pg=docs
回答4:
You can extract the contents directly using file_get_contents and parse them using json_decode.
回答5:
if you are just trying to get the info from the cocacola page in an array, I'd avoid using the Facebook library - its overly complex, and just make a simple request like:
<?php
$contents=file_get_contents('https://graph.facebook.com/cocacola/');
$json=json_decode($contents,true);
echo '<pre>';
print_r($json);
echo '</pre>';
?>
来源:https://stackoverflow.com/questions/2808172/facebook-graph-and-php-api