Imagine the situation when I'm logged in facebook web application as userA. I know userB's nickname but he is not in my friendlist and I do not know his id. And, of course, he does not use my app.
How can I get userB's id via a nickname?
After that how can I get his wall posts?
Are there any specific permissions? May be there are manual pages I've missed?
In v1.0, the following was possible:
http://graph.facebook.com/v1.0/{user-name}
However, with v2.0 and v2.1, accessing users via IDs or Usernames not connected to your application is not possible. E.g., trying http://graph.facebook.com/v2.1/{user-name} will throw an error:
{
"error": {
"message": "(#803) Cannot query users by their username (user-name)",
"type": "OAuthException",
"code": 803
}
}
Using the new PHP SDK (v4.0.x) you can do the following:
$response = (new FacebookRequest( $session, 'GET', '{user-name}', array(), 'v1.0' ))->execute()->getGraphObject()->asArray();
Related
I want to delete a facebook post or comment that is on my facebook feed. I tried to follow facebook docs,but no in vain.
Here is my code for post delete request.
$postid = "2512732972186856_2511181632341990";
$token = facebook user access token
$feed = $this->facebook->deletes($postid,array (), $token);
When I run this query it says :
{
"error": {
"message": "(#3) Publishing comments through the API is only available for page access tokens",
"type": "OAuthException",
"code": 3,
"fbtrace_id": "A9fyXxLUY3ui9S3CqiCuIDJ"
}
}
However it is important to mention that i didn't create post in page, my post is in my facebook feed.
You cannot create or delete posts on your Profile, you can only create posts on a Page, and you can only delete posts made by your App.
The error message actually tells you that those actions are only available for Pages (with a Page Token).
I am far from the programming and PHP, but got the challenge to get the Fb share count for the website :)
I'm trying to get the proper App Access Token and send the request to Fb
according to this article.
The request should be like this:
https://graph.facebook.com/?ids=http://www.myurl.com/my-page&access_token=myappid|myappsecret
And I getting this error.
{
"error": {
"message": "Invalid OAuth access token signature.",
"type": "OAuthException",
"code": 190,
"fbtrace_id": "FfZKAkCyad1"
}
}
I am going to use it in PHP roughly like this:
function facebook_count($url)
{
$results = #file_get_contents('http://graph.facebook.com/' . $url .'&access_token=myappid|myappsecret');
if ($results) {
$like_array = json_decode($results, true);
if (!empty($like_array['shares']))
return ($like_array['shares']);
}
return 0;
}
My guess, I checked wrong Permissions (scopes) for my App token. Did not found an answer in FB dev page. Checked this for now:
user_likes, read_insights, read_audience_network_insights, public_profile
What Scope do I need to check, if I need only the shares count by the link?
Or in what else could be the problem?
You need to use an App Access Token... So the actual permissions (referring to User Access Tokens!) are irrelevant.
So, hopefully you are replacing myappid|myappsecret with your actual App Id and App Secret. If ynot, there's your error. Furthermore, I think in the file_get_contents call then ?id= part in the URL is missing.
I want read the friendlist of a facebook user with fb sdk 4, but the result is always empty. I created the application on facebook for the id and key and the friendlist permission should be granted by default.
The login and retrieving profiledata works, but not the friendlist request. Here the code:
FacebookSession::setDefaultApplication($id, $key);
try {
$session = $helper->getSessionFromRedirect();
} catch(Exception $ex) { /* handle error */ }
$request = new FacebookRequest($session, 'GET', '/me/friends');
$response = $request->execute();
$graphObject = $response->getGraphObject();
print_r($graphObject);
Instead of '/me/friends' I also tried '/{fbid}/friends', '/{fbid}/taggable_friends' and some other combinations I found with google, but all with the same result.
What did I wrong? And I also want to read the list if the user is offline once an hour. Is that possible and how?
It is completely unrelated to the PHP SDK, since v2.0 of the Graph API you can only get friends who authorized your App with user_friends too.
This has been discussed in countless threads already, hereĀ“s one with a very detailed answer: Get ALL User Friends Using Facebook Graph API - Android
If you want to read stuff while the user is offline, you need to store his User Access Token and use it for an API call. Make sure you extend it though, or it will only be valid for 2 hours.
More information about Access Tokens:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
In my database some users have Facebook IDs stored, as once they logged into my website via Facebook. For each of those users I would like to store a profile picture, which would be retrieved from their Facebook accounts.
Facebook PHP SDK specifies the following way to get a user picture:
/* PHP SDK v4.0.0 */
/* make the API call */
$request = new FacebookRequest(
$session,
'GET',
'/me/picture'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
The problem is the $session param. Currently, I get the FacebookSession object after the user logs into my website via Facebook. However, for what I want to achieve, I don't have the session present.
Is it possible in PHP SDK to get Facebook user profile picture when having only the user ID, and without them being logged into Facebook?
I hope this helps,
http://graph.facebook.com/USERNAME OR USERID/picture?type=large
http://graph.facebook.com/USERNAME OR USERID/picture?type=small
http://graph.facebook.com/USERNAME OR USERID/picture?type=square
You do not need to log into facebook just use USERNAME OR USERID.
This is simple, basic thing and require only Googling...
If you're not looking for this, please elaborate the task you're doing...
Good Luck!!!
Simply use the following Graph path via GET request:
/{user_id}?fields=picture.type(large),id,name
Field type can be one of the following values:
small
normal
large
square
Or using width and/or height value like this:
/{user_id}?fields=picture.width(200).height(200),id,name
Also you can add redirect=0 param.
By default the picture edge will return a picture instead of a JSON response. If you want the picture edge to return JSON that describes the image set redirect=0 when you make the request.
So you will have the following JSON response:
{
"picture": {
"data": {
"height": 120,
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/hprofile-xaf1/v/t1.0-1/c53.10.120.120/165675_138088076251005_752993_n.jpg?oh=a9450bf53f2d2294531e11ae28be99c1&oe=56C740A5",
"width": 120
}
},
"id": "138087416251071",
"name": "Zenonis",
}
So I was wondering faecebook docs hasn't mention it in its official docs on Developers
but I have seen the graph call on blogs but it works (that's the weird thing)
https://graph.facebook.com/me/friends?method=post&uids=< USER ID>&access_token=< Acccess Token>
The respond is
{
"error": {
"message": "(#200) ",
"type": "OAuthException",
"code": 200
}
}
Is this possible to do? if yes, How can I do it with PHP SDK?
any idea is accepted
You can use the Friends Dialog. To integrate you can use javascript as-
FB.ui({
method: 'friends',
id: USER_ID
}, function(response){});
OR, a URL redirect as-
https://www.facebook.com/dialog/friends/?
id=USER_ID
&app_id=APP_ID
&redirect_uri=REDIRECT_URI
For more details: Friends Dialog