sphotos.xx.fbcdn.net Issue With Full Size Profile Pictures - facebook

I'm stuck with what is causing this issue. If i'm logged in as my account, the code below does not show user: 100000920350966 but if i logout & back into my wife's account I can now see that users profile picture.
Error I get logged into my FB account:
http://sphotos.xx.fbcdn.net/hphotos-snc6/230962_10150332269178009_784368008_9751025_7802946_n.jpg
An example of one that does work:
http://a4.sphotos.ak.fbcdn.net/hphotos-ak-ash4/419763_10151360491990078_877370077_23594484_2739927_n.jpg
the code I am using is the PHP SDK and this piece for getting an image:
function randomUser() {
$query = mysql_query("SELECT the_facebook_id FROM users WHERE the_facebook_id != '$facebook_id' ORDER BY RAND() LIMIT 0,1");
$result = mysql_fetch_array($query);
mysql_close();
return $result; }
$theuser = randomuser();
$albums = $facebook->api('/' . $theuser[0] . '/albums');
foreach($albums['data'] as $album){
if ($album['type'] == 'profile'){
$photos = $facebook->api('/' . $album['id'] . '/photos');
$random_pic = $photos['data'][0]['source'];
}
}
echo "<br /><br />The User: " . $theuser[0] . "<br />";
echo "Photo Source: " . $photos['data'][0]['source'] . "<br />";
echo "THE PHOTO HEIGHT: " . $photos['data'][0]['height'] . "<br />";
echo "THE PHOTO WIDTH: " . $photos['data'][0]['width'] . "<br />";
I honestly have no idea what when in my account I can't see particular profile pictures but in my wife's I can see all of them. All help is greatly appreciated!
Cheers

Interesting case you've got there.
I can't tell you what's wrong, but I have a guess which is divided to two options.
The urls in question are for static content and so the content is not depended on the current user.
However, that url is of a cdn, which means that the copy of the content you get is different (probably) from the copy I get, which explains how is it that you're getting an error while I'm able see the picture for the same url.
The two options:
The cdn you are directed to is not available at all and so all images you ask from it will result in page not found error. Try to ping sphotos.xx.fbcdn.net and see what you get.
The cdn you are directed to does not have a copy of the image you are trying to get, maybe for some reason an error occurred when the file was supposed to propagate to the server.
This is just a guess of course, in any case I recommend you to file a bug report and have the facebook team look it up, it might take some time for them to check it out/do something about it though.

Related

Facebook API 2.2: Graph error when trying to post a link

The goal of the script is to post automatically, on my profile and on my groups, the link to a specific page, once the content is created.
But all what I got when I launch the test script here below, is this returned string:
Graph returned an error: An active access token must be used to query information about the current user.
In fact, the token related to the app was given by FB Developers site.
I tried also the combination:
634060413388093|9ed702cc524a1cbb59ca1fb7a17839f1
But I still get the same return
<?php
$path = getcwd();
require_once $path . '/include/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => '634060413388093',
'app_secret' => '9ed702cc524a1cbb59ca1fb7a17839f1',
'default_graph_version' => 'v2.2', ]);
$linkData = [
'link' => 'http://www.example.com/page',
'message' => 'here the new page on my site.',
];
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post('/me/feed', $linkData, '634060413388093|bnTyPyRtsZSLHoc1B1w772cz3BU');
} catch (Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
echo 'Posted with id: ' . $graphNode['id'];
?>
You need to use a user access token to read the feed of a user. 'me' refers to the user that is associated with the user access token. An app access token is not associated with any specific user.
This leads to the second point, which is much more important. You should never reveal your app secret, especially not on Stack Overflow or anywhere public. You should hide that part of your SO Question, or better yet, create a new FB application.
Ok I found the way in this moment. I tried any example andy help, any suggestion but it didn't work out.
Thus, I post it hoping it helps somebody else with my same issue:
The access token, is not app_id|app_secret but it's obtained in another way:
To get the correct access otken, one should go to:
https://developers.facebook.com
under "Tools & Support" select "Graph API Explorer"
On the upper right corner, there is a drop down menu called "Application".
Click and select the created application.
Select "Access Token" shown, and copy/paste it in the field aside $linkDAta variable:
$response = $fb->post('/me/feed', $linkData, '{access-token}');
At that point, launching the script as it is, it worked out :)
EDIT:
If you need to post in groups, just change the '/me/feed' with '{group_id}/feed'

Facebook page tab app session across subpages PHP SDK 4

See the full original question further down
Using the latest Facebook PHP SDK 4.4.0, in my main app page I can do the following to get a user id etc.
<?php
FacebookSession::setDefaultApplication(APP_ID, SECRET);
$helper = new FacebookRedirectLoginHelper( PAGE_URL );
$pageHelper = new FacebookPageTabHelper();
$session = $pageHelper->getSession();
echo '<p>You are currently viewing page: '. $pageHelper->getPageId() . '</p>';
// get user_id
echo '<p>User Id: ' . $pageHelper->getUserId() . '</p>';
// **depcrecated** get like status - use for likegates
echo '<p>You have '. ( $pageHelper->isLiked() ? 'LIKED' : 'NOT liked' ) . ' this page</p>';
// get admin status
echo '<p>You are '. ( $pageHelper->isAdmin() ? 'an ADMIN' : 'NOT an ADMIN' ) . '</p>';
?>
This does not work on sub pages of my app ... Why is the session (and amongst other things, the signed request) lost? How can I get them back and how can I get methods such as getUserId() from the the FacebookPageTabHelper to continue to work on sub pages?
full original question
I'm fairly new to Facebook app development and I'm having problems with session management and I just can't seem to be able to wrap my head around it. Of course it doesn't help that the official documentation is almost useless.
My problem is that the page session get lost when moving away from the apps main page to a subpage within the Facebook page tab app iframe.
I use the following PHP code to obtain the session and user id on the main (initial) app page and it works great:
<?php
FacebookSession::setDefaultApplication(APP_ID, SECRET);
$helper = new FacebookRedirectLoginHelper( PAGE_URL );
$pageHelper = new FacebookPageTabHelper();
$session = $pageHelper->getSession();
?>
But it doesn't work on sub pages :( when a user clicks on a menu item (or any other link inside the app/iframe), the session goes bye bye. Which is not ideal as I need the user id of the user to track whether or not that user has completed certain actions. Of course I could send the ID along with every request, but there must be a way to have a persisting session, no?
Is there a way to retrieve the session on a sub page in PHP? If so, how? Or do I have to load additional content using javascript? And how would that work, if I can't keep the session between requests and therefore have no way of identifying which user a request came from? How do others handle this?
What I'd like to avoid is to write my own user session management, which would solve the problem but is simply not in the budget and I was hoping I could work with what Facebook already had on offer. Especially since my app doesn't require user information/permissions of any kind.
Thanks a lot in advance for any info on this topic, greatly appreciated, going in circles here.
Edit to clarify: I thought of just saving the Facebook session in a PHP session cookie, but how would I use that to reconnect with Facebook after changing the page?
I finally managed to solve this problem. I'm not sure whether this is considered the right way or can even be a recommended way of doing this, but it works and since time is of the essence, I don't have much of a choice.
If anybody has any further ideas or suggestions, please comment.
Here's how I did it:
// store the signed request
if(isset($_REQUEST['signed_request'])) {
$_SESSION['signed_request'] = $_REQUEST['signed_request'];
} elseif($_SESSION['signed_request']) {
$_REQUEST['signed_request'] = $_GET['signed_request'] = $_POST['signed_request'] = $_SESSION['signed_request'];
}
// assign the stored signed request to REQUEST, GET and POST vars (the unsavory bit, imo)
$_REQUEST['signed_request'] = $_GET['signed_request'] = $_POST['signed_request'] = $_SESSION['signedRequest'];
FacebookSession::setDefaultApplication(APP_ID, APP_SECRET);
$accessToken = APP_ID . '|' . APP_SECRET;
$this->session = new FacebookSession($accessToken);
$pageHelper = new FacebookPageTabHelper();
$isAdmin = ($this->pageHelper->getPageData('admin')) ? $this->pageHelper->getPageData('admin') : 0;
// get pade id
echo '<p>You are currently viewing page: '. $pageHelper->getPageId() . '</p>';
// get user_id
echo '<p>User Id: ' . $pageHelper->getUserId() . '</p>';
// get admin status
echo '<p>You are '. ( $isAdmin ? 'an ADMIN' : 'NOT an ADMIN' ) . '</p>';

how to allow users of a website to email their contacts?

I just would like some guidance as to where to start this project. If I want to enable users of my website, to email all their contacts about an update (similar to linkedin does when you join) how should I go about doing this? I honestly have no idea where to begin.
I'd start by looking at OAuth - the user allowing your service access of some form to their account. You can start with Google's API info here:
https://developers.google.com/accounts/docs/OAuth2
I don't know what programming language you are writing this in so heres some pseudocode.
foreach contacts in databaseresults{
$To = '"' . $databaseresults['first_name'] . '" <' . $databaseresults['email'] . '>';
$Headers = "From: \" Some Company \" <support#reallycooldomain.com>"."\r\n".
"Content-type: multipart/mixed; boundary=$someMD5Hash"."\r\n";
$Message = "--$someMD5Hash\r\nContent-Type: text/html;" . "\r\n" . $someHTMLContent . "\r\n\r\n" . "--$someMD5Hash--";
$subject = "A Squirrel Added a Nut to your pile!";
mail($To,$Subject,$Message,$Headers);
}
At least thats some PHP to work

file_get_contents() doesn't return FQL results even if the fql itself in url works

Type this query in url bar, it works. I can get the results on the browser window.
https://graph.facebook.com/fql?q=SELECT+actor_id+FROM+stream+WHERE+post_id+IN+(SELECT+post_id+FROM+stream+WHERE+filter_key+in+(SELECT+filter_key+FROM+stream_filter+WHERE+uid=me()+AND+name='Links')+AND+attachment.caption+in+('xxxx.com','xxxx.com')+AND+type=80+AND+created_time%3C=now()+LIMIT+20)+ORDER+BY+created_time+DESC+&access_token=xxxx...
But php code below doesn't. file_get_contents() returns empty array.
$fql_query_url = 'https://graph.facebook.com/'
. 'fql?q=' . str_replace(' ', '+', $query1)
. '&access_token=' . $access_token;
$fql_query_result = file_get_contents($fql_query_url);
The query mentioned above is dump of $fql_query_url.
App already has got permissions below.
read_stream
read_insights
Does anyone know anything?
I finally solved it by myself.
attachment.caption in xxxx
was the cause of no results regardless of that it works when you type query in url bar.

How do I echo something from Facebook's graph api?

I want to display the content from: https://graph.facebook.com/comments/?ids=http://lujanventas.com/test.php in my site.
How can I do it aside from an AJAX call? Can it be done without JS?
you can create a server side script that reads the content of the file and echos it
this is an example for such script in php:
$ids = "http://lujanventas.com/test.php";
$url = "https://graph.facebook.com/comments/?ids=".urlencode($ids);
$data = json_decode(file_get_contents($url),true);
foreach($data[$ids]["comments"]["data"] as $comment){
echo $comment["message"]."<br /><br />";
}