After successfully signing up, i'm getting users Facebook pictures in this way
/*
* Get user profile picture
*/
try {
// Returns a `FacebookFacebookResponse` object
$response = $fb->get(
'/' .$fbUserProfile['id'] . '/picture',
$_SESSION['facebook_access_token']
);
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$avatar = $response->getHeaders()['Location'];
$this->model_account_customer->addCustomerAvatar($avatar, $this->customer->getId());
So far so good, but the pictures size is 50x50 :( . I read all similiar questions here, but none of them helped me. Also, i've tried to add type=large , i've changed the $response array like that
$response = $fb->get(
'/' .$fbUserProfile['id'] . '/picture',
$_SESSION['facebook_access_token'],
array(
'type' => 'large'
)
);
Still not working. Any ideas would be appreciated :)
Related
Following at the Facebook API docs I'm able to return only 4 attributes from my FB app.
My Code:
$user = Auth::user();
try {
$response = $this->facebook->get('/'.$user->facebook_app_id, $user->facebook_access_token);
} 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();
dd($graphNode);
This only returns 4 attributes
I need it to also return app_domains. Looking at the docs it looks like it should? Is there a way to return the app_domains array from a FB app? FB app API
Looks like you'll need to use something like this:
$response = $this->facebook->get('/'.$user->facebook_app_id,
['fields' => 'app_domains'],
$user->facebook_access_token
);
I have the following PHP code to post in a Facebook Group Feed where the the publisher is admin of. The code is as follows:
$post_array=array ('link'=>$link_share,'message' => $message);
try {
$response = $fb->post(
"/{$group_id}" . "/feed",
$post_array,
"{$access_token}"
);
} 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();
But when I execute it I get the error:
Graph returned an error: Unsupported post request. Object with ID 'group_id' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
I read all the documentation, the user has the permissions to publish in the group but I keep getting that error. Any ideas why?
Thanks
I am super new to this so I apologize if this has a simple solution.
I've got a file running every 12 hours to search the database for new entries. If there is a new entry, it gets posted to the Facebook page. It works, but it only posts one entry even if two or more are in the query.
It might just be that I have the if statement in the wrong place, but I'm just stuck trying to figure it out.
I'd be grateful for any advice or link to tutorial.
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc() ) {
$linkData = [
'link' => $url,
'message' => 'Thank you for the positive review!' . "\r\n\r\n" . '"' . $row["review"],
];
try {
$response = $fb->post('/me/feed', $linkData, $pageAccessToken);
} 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();
}
}
I want to get following local insights of Facebook page using graph API
People Nearby:Hourly
Weekly
Overall
Check-ins
Please see the screen shot.
Image
You can get page insights by using this code and ask for page permissions ('manage_pages','pages_manage_cta') , and get page id first from your likes or managed pages and replace you page id in code with YOUR_PAGE_ID.
use FB php sdk version: facebook-php-sdk-v4-5.0-dev.
$fb = new Facebook\Facebook([
'app_id' => APP_ID,
'app_secret' => APP_SECRET,
'default_graph_version' => 'v2.4', // or use v2.5 latest version
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['manage_pages','pages_manage_cta'];
$redirectUrl = 'http://localhost/fbapp.php';
$loginUrl = $helper->getLoginUrl($redirectUrl, $permissions);
echo 'Log in with Facebook!';
After generating login url implement the code for response handling and getting required data.
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
setcookie('accessToken',$accessToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$fb->setDefaultAccessToken($accessToken);
// Get user groups detail
$requestPageInsights = $fb->request('GET', '/YOUR_PAGE_ID/insights');
//Make a batch request
$batch = ['page-insights' => $requestPageInsights];
try {
$responses = $fb->sendBatchRequest($batch);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
for a better view can use this:
foreach ($responses as $key => $response) {
if ($response->isError()) {
$e = $response->getThrownException();
echo '<p>Error! Facebook SDK Said: ' . $e->getMessage() . "\n\n";
echo '<p>Graph Said: ' . "\n\n";
var_dump($e->getResponse());
} else {
echo "<p>(" . $key . ") HTTP status code: " . $response->getHttpStatusCode() . "<br />\n";
echo "Response: " . $response->getBody() . "</p>\n\n";
echo "<hr />\n\n";
}
}
And for getting other details visit on and use your related params/scope https://developers.facebook.com/docs/graph-api/reference/v2.5/insights
I used to create several apps before, but now with the v4 I can't make a simple photo upload to work :( I tried with the 'url' and with the 'source' parameter as well, but nothing works. I want to upload a photo to my own Facebook Page with some caption. I got the access token, the Access Token Debugger says, that it never expires and it has public_profile, read_stream, read_insights, manage_pages, publish_actions, user_photos permissions.
This my code right now:
$accessToken = "MY-ACCESS-TOKEN";
$session = new FacebookSession($accessToken);
$myfile = "file.png"; //created and saved via PHP GD functions
if ( isset( $session ) ) {
try {
$message = "This is my message";
$request = new FacebookRequest(
$session,
'POST',
'/'.$pageid.'/photos',
array (
'source' => realpath("/path/to/" . $myfile),
'message' => $message,
)
);
} catch (FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
} catch (\Exception $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
} else {
// show login url
echo 'Login';
}
Right now I get this error:
mod_fcgid: stderr: PHP Fatal error: Uncaught exception 'Facebook\\FacebookAuthorizationException' with message '(#324) Requires upload file' in /data/domains/
What am I doing wrong? Can someone help me, please?
Thank you very much!