This is my View
<div class="clear doc-buttons" style="padding-left: 2%; margin-top: 9px;">
<?php
$app_id = 'APP_ID';
$app_secret = 'SECRET KEY';
$return_url = 'example.com/project/event/customer/main/return';
$dialog_url = "facebook.com/dialog/oauth?client_id=".$app_id . "&redirect_uri=".urlencode($return_url)."&scope=email,read_stream,create_event";
?>
<a href="<?php echo $dialog_url; ?>" class="btn btn-s-md btn-facebook">Import from <strong>facebook</strong></a><br>
<small class="text-muted text-uc">Import From Facebook</small>
</div>
This is my controller
public function actionReturn() {
include (YiiBase::getPathOfAlias('webroot') . '/facebook-php-sdk/src/base_facebook.php');
include (YiiBase::getPathOfAlias('webroot') . '/facebook-php-sdk/src/facebook.php');
$app_id = 'APPID';
$app_secret = 'SECRET KEY';
$return_url = 'localhost/project/event/customer/main/return';
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['code'])) {
$code = $_POST['code'];
}
include (YiiBase::getPathOfAlias('webroot') . '/facebook-php-sdk/src/fb_ca_chain_bundle.crt');
//provide the path where you have stored the facebook API
$token_url = "graph.facebook.com/oauth/access_token?client_id=" . $app_id . "&redirect_uri=" . urlencode($return_url) . "&client_secret=" . $app_secret . "&code=" . $code . "&scope=email,read_stream,create_event";
//Getting access_token using curl method
$c = curl_init($token_url);
curl_setopt($c, CURLOPT_HTTPGET, true);
curl_setopt($c, CURLOPT_FRESH_CONNECT, true);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($c, CURLOPT_CAINFO, $cert);
$output = curl_exec($c);
if ($output === false) {
curl_close($c);
return false;
}
curl_close($c);
$curltoken = explode('&', $output);
$token = explode('=', $curltoken[0]);
foreach ($token as $singletoken) {
$oneToken = $singletoken;
}
echo $oneToken . '<br/>';
if (empty($oneToken)) {
echo 'Something went wrong';
//here redirect back to the page throwing error “No Facebook Connection”…
}
//Facebook API function to get the event details from FB
$facebook = new Facebook( array('appId' => $appid, 'secret' => $secret, 'cookie' => true));
$attachment = array('access_token' => $oneToken, 'limit' => 100);
$container = array();
try {
$user = $facebook -> api('/me', 'GET', $attachment);
echo "Your Detail is ";
print_r($user);
$events = $facebook -> api('/me/events', 'GET', $attachment);
if (!empty($events) && !empty($events['data'])) {
echo "$events is not empty";
foreach ($events['data'] as $event) {
$objResult = $facebook -> api($event['id'], 'GET', $attachment);
if (!empty($objResult)) {
echo "$objResult is not empty";
$fevent = new stdClass();
$fevent -> id = $objResult['id'];
$fevent -> EventName = $objResult['name'];
$fevent -> EventDescription = $objResult['description'];
$fevent -> EventStartDate = isset($objResult['start_time']) ? strtotime($objResult['start_time']) : time();
$fevent -> EventEndDate = isset($objResult['end_time']) ? strtotime($objResult['end_time']) : time() + 7200;
$fevent -> EventHost = isset($objResult['owner']['name']) ? $objResult['owner']['name'] : "";
$fevent -> Location = isset($objResult['location']) ? $objResult['location'] : "";
$fevent -> LocationStreet = isset($objResult['venue']['street']) ? $objResult['venue']['street'] : "";
$fevent -> LocationCity = isset($objResult['venue']['city']) ? $objResult['venue']['city'] : "";
$fevent -> LocationState = isset($objResult['venue']['state']) ? $objResult['venue']['state'] : "";
$fevent -> LocationCountry = isset($objResult['venue']['country']) ? $objResult['venue']['country'] : "";
$fevent -> LocationLat = isset($objResult['venue']['latitude']) ? $objResult['venue']['latitude'] : "";
$fevent -> LocationLon = isset($objResult['venue']['longitude']) ? $objResult['venue']['longitude'] : "";
$eventList[] = $fevent;
}
}
}
} catch (Exception $e) {
//here redirect back to the page throwing Exception error – $e->getMessage()…
print_r($e);
}
print_r($eventList);
if (!empty($eventList)) {//array of list obtained from the previous step
//foreach ($eventList as $event) {
print_r($eventList);
//}
} else {
}
}
Now When i click on the link Import from facebook the action opens a login page and user gets logged in but when facebook returns the result on the $return_url it Gives the
[b]
Error 400
Your request is invalid.
[/b]
Is there any one please help me THANXX IN ADVANCE