Ask facebook to re-scrape URL automatically - facebook

how can I make a php code for facebook to automatically update the cache of a single url
I saw something similar in other threads, but did not manage to make it work:
Is there an API to force Facebook to scrape a page again?
Ask facebook to re-scrape URL

For example use this php code, adding the url of my web www.tolchx.net, but it still appears the same GIF when I go to debugging:
<?php
try {
$params = [
'id' => 'https://www.tolchx.net',
'scrape' => 'true',
];
$response = $fb->post('/', $params);
print_r($response);
} catch(\Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
} catch(\Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
}
?>
With that enough to automatically update the link cache www.tolchx.net?
thanks for the reply

Related

Graph API Facebook SDK for PHP Permissions Error

I am working on Auto Posting on facebook page or group by using graph api. But i get error of permissions but i allow permissions But i face this error. Any one who know about this error.
Code given below.
I share some images Which error showing me or how to allow permissions.
<?php
require_once ('vendor/autoload.php');
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.10',
]);
$pageAccessToken = '{page-access-token}';
$MsgData = [
'message' => 'Hi, My name is Zaheer'
];
try {
$response = $fb->post('/me/feed/' , $MsgData , $pageAccessToken );
}
catch ( \Facebook\Exceptions\FacebookResponseException $e ) {
echo 'Graph returned an error ' . $e->getMessage();
exit;
}
$GraphNode = $response->getGraphNode();
echo 'ID :' . $GraphNode['id'];
?>
[![enter image description here][2]][2]
Debug your Token: https://developers.facebook.com/tools/debug/accesstoken
You can see that it is a User Token, not a Page Token. Page Tokens can be generated by using a User Token with the following endpoints:
/me/accounts?fields=access_token
/page-id?fields=access_token
Make sure to use page token. You can easily get one from the the graphi api explorer on the right panel. I was having permissions error. My app type was business and to remove it, I just added all the permissions from the given list and after I added all permissions, facebook asked me to review permissions, I simply kept clicking on OK and everything worked, the error went :D

Cannot fetch E-Mail from Facebook SDK

Cannot fetch E-Mail address from facebook SDK for some particular E-Mail accounts. The facebook account I am testing with do have their E-Mail address in facebook. I am having this issue for some particular accounts only. Is there any settings which I have to activate from facebook. To fetch E-Mail I am using PHP Facebook SDK, the code is listed below:
$fb = new Facebook\Facebook([
'app_id' => 'xxxxxxxxx',
'app_secret' => 'xxxxxxxxxxxxx',
'default_graph_version' => 'v2.11',
]);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me?locale=en_US&fields=id,name,email', $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;
}
$user = $response->getGraphUser();
echo '<pre>';
var_dump($user);
exit;
If I use artdarek/oauth-4-laravel I can fetch the E-Mail address for the exceptional cases as well. But as the project is live I cannot Install the same in live server. Please suggest an alternative way out with PHP Facebook SDK.

How to get images from FB to website

I'm working on publishing posts from our FB page on our website. Each new post and photos we added into our FB page I need to show in our website too.
I have this code, but don't working as I need.
require 'php-graph-sdk-5.x/src/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => '...',
'app_secret' => '{app-secret}', // don't know where to find app_secret for my page, I've found that just for apps, not pages
'default_graph_version' => 'v2.10'
]);
$access_token = '...'; // generated in developers, but with just for 12 hours, than this token is expired... :-(
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('me?fields=id,name,feed,data', $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();
foreach ($graphNode as $node) {
foreach ($node as $items) {
print_r($items);
// when access token was valid, I got posts from out FB page. But with no images, didn't find how to get add images to this feed...
}
}
So, my questions are:
where I can find app-secret for FB page? I'm not able to connect to my FB page without that, I think
how to generate permanent access token, or if it's not possible, how to make i other way?
how to add images (new, shared, etc.) to my feed?
Thanks.
There is no App Secret per Page, there is only the App Secret per App. You can find it in your App Settings.
Extended/Permanent Tokens: https://developers.facebook.com/docs/facebook-login/access-tokens/ or http://www.devils-heaven.com/facebook-access-tokens/ - for getting the feed entries of unrestricted Page, you can just use an App Access Token and you can hardcode it in your PHP code.
Getting images in the feed, not just messages: You need to specify which fields you want to get, or you will only get default ones. It is called "Declarative Fields": https://developers.facebook.com/docs/graph-api/changelog#v2_4 - also, check out the API reference: https://developers.facebook.com/docs/graph-api/reference/post

FaceBook PHP API SDK: suddenly the argument 'link' is not published and /me/feed is not working

I completed this script, that was working fine till this morning, when launching it, suddenly I noticed that the argument "link" of the array $linkData, is not published any longer, (no error returned) while "message" is published.
I also noticed that if I put /me/feed into the object $fb->post, it doesn't work (see the commented line). No errors returned.
While, if I put the code of a group (the code you see is a test group I created to test the script), the argument "message" is published (not the "link")
The scopes are:
user_managed_groups,
user_events,
user_friends,
user_posts,
publish_actions,
user_actions.music,
user_actions.video,
public_profile
The link is referred to the link for which the application is written. the www.example.com URL, is written here for this example. In the real code, I use the URL of the site of the App (that till yesterday was working fine).
Please here the code:
<?php
session_start();
define(__APP_ID__, XXXXXXXXXXXXXXX);
define(__APP_SECRET__, 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY');
define(__APP_TOKEN__, 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ');
define(__APP_ACCESS_TOKEN__, 'WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW');
require_once '../include/setup.php';
require_once $root_dir.'/include/Facebook/autoload.php';
// Creates the object
$fb = new Facebook\Facebook([
'app_id' => __APP_ID__,
'app_secret' => __APP_SECRET__,
'default_graph_version' => 'v2.2',
]);
$linkData = [
'link' => 'http://www.example.com',
'message' => 'The link above, is not any longer published',
];
$group_id = "1041863359178529";
try {
//$response = $fb->post("/me/feed", $linkData, __APP_ACCESS_TOKEN__); // SUDDENLY it doesn't work any longer
$response = $fb->post("/{$group_id}/feed", $linkData, __APP_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();
echo 'Posted with id: ' . $graphNode['id']."\r\n";
?>
EDIT:
Is there anything I can do? Is id depending from the App settings? I changed many parameters to find a solution but I still have the issue.
I did verified that the block, is due FB.
In other words: probably of security reasons (mainly Anti-Spam), FB block repetitive use of the function in short time.
I did try also to wait more than 15 seconds among the iterations, but if I employ it for more than 20-25 time in one day, FB suspends all the required authorizations.
At the time I did post the thread, FB was enabling only the post of the text, and deactivated OpenGraph.
Now, instead, it blocks any kind of sending, including text.

How to get specific fields with Facebook API/SDK

I'm playing around a bit with Facebook API + PHP SDK but I'm stuck..
I'm trying to fetch all my wall posts and (if attached) the images.
Fetching all my posts goes fine but it doesn't automatically include the image. So my main question is 'How can I add fields to the fetch command'
Here is the code I'm using now:
/* handle the result */
try {
$response = $fb->get('/me/posts', $token);
} 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;
}
// Page 1
$feedEdge = $response->getGraphEdge();
According to the facebook documents I should use this:
$request = new FacebookRequest(
$session,
'GET',
'/me/posts',
array(
'fields' => 'full_picture,message'
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
But the execute and getGraphobject method don't even exist in my SDK files (which is the latest version)
To get specific fields, you can try changing
$response = $fb->get('/me/posts', $token);
to
$response = $fb->get('/me/posts?fields=full_picture,message', $token);