i want to get page insights data from 2014-08-01 to 2014-08-31 but problem is i am getting data to 2014-08-30 date only. if i am giving until date 2014-08-30 it will give me data to
2014-08-29. whatever i give date it show me result of until date - 1.
$get_data = array(
'access_token' =>'my access token'
'period' => 'day',
'since' => '2014-08-01',
'until' => '2014-08-31',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'page id'/insights/?'.http_build_query($get_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$oResult2 = curl_exec($ch);
curl_close ($ch);
$oResult2 = json_decode($oResult2);
foreach($oResult2->data as $oData)
{
print_r($oData);
}
I’ve solve my problem... i have to pass date like this
'since' => '2014-08-01 00:00:00',
'until' => '2014-08-31 23:59:59',
Related
How get list of transactions with all my btc addresses with HD account to json format. PHP. I need in link for it
$json_url = "http://127.0.0.1:3000/merchant/$guid/accounts/0?password=$pass";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $json_url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$content = json_decode(curl_exec($ch));
curl_close ($ch);
i have this problem with my FB-App
i have 2 files..
1) the mainApp.php .. and ..
2) the asyncApp.php .. (which processes data, delivers content & shit..)
and now..
when a user logs in, everything works fine.. i get the access-token and save it to a SESSION-Var..(only mainApp.php is processed here).. but..
when i call the async.php via jquery.load() e.g. .. i always get the
{"error":{"message":"Malformed access token .. oO
but the token is the same i get from FB in the mainApp.php.. :(
mainApp:
this way i get the Token..
if(isset($_GET["code"])) {
$code = $_GET["code"];
$url = 'https://graph.facebook.com/oauth/access_token?client_id='.$appID.'&redirect_uri='.urlencode($appRedirectURI).'&client_secret='.$appSecret.'&code='.$code;
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,6);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if(strpos($buffer, 'access_token=') === 0) {
//if you requested offline acces save this token to db for use later
$token = str_replace('access_token=', '', $buffer);
$_SESSION['fbToken'] = $token;
later i call the async.php which should do a feed on the users wall..
$attachment = array(
'access_token' => $_SESSION['fbToken'],
'message' => 'dfdfdf',
'name' => 'sdfdsf',
'link' => 'http://www.mbla.de',
'description' => 'sdfdsf',
'picture'=> '',
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/me/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);
would be nice if someone could help me.. i'm suffering almost 2 weeks now.. :(
Welcome to Stack Overflow!
What happens when you call async.php directly, does it work?
What happens when you have the script print_r() the contents of $_SESSION, is it populated?
What about if you do it through an ajax call, and inspect the output through Firebug/Chrome Inspector?
Looking at the code attached (async.php), it looks like you're not passing in the parameters properly to Facebook. The curl option CURLOPT_POSTFIELDS does not take an array as an argument. Instead, it should be constructed as a query string:
curl_setopt($ch, CURLOPT_POSTFIELDS, 'param1=value¶m2=value¶m3=value');
For ease, I tend to do this instead:
curl_setopt($ch, CURLOPT_POSTFIELDS, htmlspecialchars(http_build_query(array(
"param1" => 'value',
"param2" => 'value',
"param3" => 'value'
))));
How to post a notification to users as application using facebook php sdk?
I have attached an image, in that picture we can see application from SongPop post a notification to me. I want to make something like this. I think this app post notification to their users, can I post a notification to a spesific user?
you have to a canvas page url set to in your app config then try with this code
$url = "https://graph.facebook.com/$user_id/notifications";
$notification_message = 'My Example Notification Message';
$app_access_token = $app_id . '|' . $app_secret;
$attachment = array(
'access_token' => $app_access_token, // access_token is a combination of the AppID & AppSecret combined
'href' => '', // Link within your Facebook App to be displayed when a user click on the notification
'template' => $notification_message, // Message to be displayed within the notification
);
// set the target url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);
$profile_id = $userInfo['id'];
$picLocal = "https://xxxxxxxxxx/logo.jpg";
$attachment = array('access_token' => $decodedSignedRequest['oauth_token'],'message' => $userInfo['name'].' is in the draw to win a Free wine for a year',
'name' => "Oliver's taringa",
'link' => $fbconfig['appPageUrl'],
'description' => 'Oliver\'s Taranga in McLaren Vale is home to the ultra-premium HJ Reserve Shiraz and has supplied grapes for the illustrious Penfolds Grange, arguably the pinnacle of achievement for Shiraz growers in Australia. So join their community to go in the draw to win a years worth of amazing wine!',
'picture' => $picLocal
);
if(!($sendMessage = $facebook->api('/'.$profile_id.'/feed/','post',$attachment))){
$errors= error_get_last();
echo "Facebook publish error: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
}
before 3 days this code work for all applications. but from last 3 days i see message etc post, only picture we not able to see on news.
http://i.stack.imgur.com/n06Jj.jpg
the following code is working for me nicely .
$data = array(
"link" => $link,
"access_token" => $user_access_token,
"picture" => $image,
"name"=> $title,
"description"=> $description
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/".$userId."/feed");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$op = curl_exec($ch);
if (!$op) {
echo "Curl Error : ".curl_error($ch);
curl_close($ch);
exit;
}
curl_close($ch);
$res = get_object_vars(json_decode((string)$op));
print_r($res);
I am quite confused using the Facebook application in the iframe. I granted permissions to the app and accessed to it, but the application acts very strange. If I try to test myself withe the code:
$app = array(
'appId' => 'yyy',
'secret' => 'xxx',
'cookie' => true
);
$facebook = new Facebook($app);
$user_id = $facebook->getUser();
I get 0. On the other hand, if I use this kind of code:
$canvas_page = 'http://www.bandito.sk/facebook/canvas.php';
$auth_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=user_about_me,user_birthday,email,user_status";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
I get all what I need. But I just don't understand, the Facebook doesn't even send a signedRequest() in the first example. Do I have to login even tough I use the application inside Facebook as a canvas page?
OK found it on my own
$request_ids = explode(',', $_REQUEST['request_ids']);
print_r($request_ids);
foreach($request_ids AS $request_id){
$request_uri=$request_id."_".$data[user_id];
$ch = curl_init('https://graph.facebook.com/'.$request_uri.'&access_token='.$data[oauth_token]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
$response = curl_exec($ch);
var_dump($response)."<br>";
}