I'm trying to get the events/not_replied from me, but all I get is an empty array....
I've tried those:
$facebook->api('/me/events/not_replied','GET');
and
$facebook->api('/me/events/not_replied');
and
$access_token = $facebook->getAccessToken();
$url = 'https://graph.facebook.com/me/events/not_replied?access_token='.$access_token;
$string = file_get_contents($url);
$json_a=json_decode($string,true);
and etc...
none works. Any idea?
You need to request the "user_events" permission.
Related
I am not able to get the Facebook friends list using the API. It was working fine earlier but not anymore. Here is the code I have used. Can someone help to validate the code. Thanks in advance.
<?php
require_once('PHPMailerAutoload.php');
require_once('PHPMailerConfig.php');
require_once("facebook/facebook.php");
$config = array();
$config['appId'] = '***************';
$config['secret'] = '*******************************';
$facebook = new Facebook($config);
$uid = $facebook->getUser();
if(!empty($_GET['error'])) {
echo "User cancelled the authentication with facebook";
echo "<script>
window.opener.location.href='merror.php';
window.close();
</script>";
exit;
}
if($uid) {
$url = $uid.'?fields=id,work,friends,email,picture.width(450).height(450)';
$user_profile = $facebook->api($url);
$friends = $facebook->api('/me/friends');
$d = '';
foreach($friends['data']as $val) {
$d .= $val['id'].',';
}
}
?>
Please read the docs before posting a question which has been answered here hundreds of times.
See
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/friends#read
A user access token with user_friends permission is required to view the current person's friends.
This will only return any friends who have used (via Facebook Login) the app making the request.
If a friend of the person declines the user_friends permission, that friend will not show up in the friend list for this person.
i still have a problem on http://www.whaelse.com/en/grau-gruen-schwarz/ with the share counter.
Twitter and Google+ works fine for me.
With this code i've tried to load the facebook shares.
function get_likes($url) {
$json_string = file_get_contents('https://graph.facebook.com/?id='.$url);
$json = json_decode($json_string, true);
return intval( $json[$url]['shares'] );
}
and then
function getSocialCount($url){
$urlCurrentPage = get_permalink($post->ID);
$strPageTitle = get_the_title($post->ID);
echo '<li>facebook<span class="facebooksticky">'.get_likes($url).'</span></li>';
}
echo getSocialCount( get_permalink($post->ID));
but i still get 0 shares counter.
Could be a caching problem, just try it again tomorrow. Or try this endpoint, used by sharedcount.com:
https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json
I want to get last of redirect URL.
like
url_1 : http://on.fb.me/4VGeu
url_2 : https://www.facebook.com/
I want to get url_2 by url_1 in perl.
Previous source is below.
sub get_redirect_location
{
my ($url) = #_;
my $ua = LWP::UserAgent->new;
$ua->proxy('http', 'SAMPLE_PROXY');
my $req = new HTTP::Request(GET => $url);
my $res = $ua->request($req);
return $res->headers_as_string;
}
Thanks in advance.
You can find the request that lead to a response using
$response->request()
You can get the previous response in the chain using
$response->previous()
All together:
while ($response) {
say $response->request()->uri();
$response = $response->previous();
}
You could look at WWW::Mechanize. I have used it before to do something like this.
http://search.cpan.org/~jesse/WWW-Mechanize-1.72/lib/WWW/Mechanize.pm#$mech->redirect_ok()
You may also find this post helpful:
Perl WWW::Mechanize (or LWP) get redirect url
Making a simple request like:
$client = new Zend_Http_Client('http://example.org');
$response = $client->request();
How can I get the final URL after the redirects?
I have not seen a way in the documentation or the API docs unless I'm missing something.
Thanks in advance.
Zend_Http_Client update the last URL into Zend_Http_Client->uri property if there is redirect.
$sourceUrl = 'http://google.com';
$client = new Zend_Http_Client($sourceUrl);
$response = $client->request();
$finalUrl = $client->getUri()->__toString();
var_dump($sourceUrl);
// string(17) "http://google.com"
var_dump($finalUrl);
// string(25) "http://www.google.com:80/"
Not tested :
$response->getHeader('Location');
Get the last request from the client and then extract the headers.
$client = new Zend_Http_Client('http://webonyx.com');
$response = $client->request();
$lastHeaders = Zend_Http_Response::extractHeaders($client->getLastRequest());
// $lastHeaders['host'] will be your final redirected host
I have written a small piece to get the user to login :
<?php
include_once ('facebook.php');
$api_key = 'xxxxxxxxxxxxx';
$secret = 'xxxxxxxxxxxxx';
global $facebook;
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
#Ask user to login if not logged in
$is_tab = isset($_POST['fb_sig_in_profile_tab']);
if( !$is_tab ){
$uid = $facebook->require_login($required_permissions = 'email,status_update,offline_access');
}
else{
$uid = $facebook->get_profile_user();
}
I need to retrieve the users info once I have the uid. Unfortunately I cannot find the api calls for it and there is a no IDE for facebook :(. Can anyone point me to the api's or give me here. I want to get users username, city, zipcode.
I coudnt get this to work : facebook.Schema.user user = api.users.getInfo();
I think it is for the new API lib.
Thanks.
P.S: I am not using graph APIs, because I found them to be poorly documented and I got stuck with them for a while so decided to abandon them atleast for now.
You can get it like this:
$user_info = $facebook->api_client->users_getInfo($uid, "name, city, zipcode");
print_r($user_info);
More Info:
http://developers.facebook.com/docs/reference/rest/users.getInfo