$fburl = "/XXXXXXXXXX/posts?fields=$fields&limit=25$nav";
echo "FBURL: $fburl<br />";
$request = new FacebookRequest( $session, 'GET', "$fburl");
$response = $request->execute();
$FBdata = json_decode($response->getRawResponse());
$fbatturl = urlencode("/$postid?fields=attachments");
echo "FBATTURL: $fbatturl<br />";
$request = new FacebookRequest( $session, 'GET', "$fbatturl");
$response = $request->execute();
$FBattdata = json_decode($response->getRawResponse());
I'm stuck here. In a web page The first fburl group iterates through the 25 posts but I can't get the call to each posts' attachments to run. The error is:
Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message '(#803)
Some of the aliases you requested do not exist: aaaaa...aaaaa_aaaaaaaaa..aaa?fields=attachments'
in C:\wwwroot\....php-sdk4\FacebookRequestException.php:134 Stack trace: #0
C:\wwwroot\.,..php-sdk4\FacebookRequest.php(268):
Facebook\FacebookRequestException::create('{"error":{"mess...', Object(stdClass), 404) #1 C:\wwwroot\.....php(386): Facebook\FacebookRequest->execute() #2 {main} thrown in C:\wwwroot\....\php-sdk4\FacebookRequestException.php on line 134
The 'FBatturl' echoed in the error messages work in the Graph Explorer (2.1).
Following this example Facebook PHP SDK4 - FQL Request I've tried ...
$params = urlencode("SELECT attachment FROM stream WHERE source_id=$StatusID[0] AND post_id=\"$postid\"");
$request = new FacebookRequest( $session, 'GET', $params );
$response = $request->execute();
$FBattdata = json_decode($response->getRawResponse());
and received the same error and I'm assuming the attachments are defunct. They were getting very problematic.
Where from here?
It should be possible to get the photos from the post link? Did I read there would be photos with posts in the new SDK?
The "attachments" (media content associated with a story or comment) are now edges with the post ...
https://developers.facebook.com/docs/graph-api/reference/v2.2/post/
https://developers.facebook.com/docs/graph-api/reference/v2.2/story_attachment
Related
I'm trying to post on my Facebook page with PHP.
I have set up the Facebook API (version 4) and collected all the data I need, like AppId, Secret Key, Access Token and now when I try to post on my page like this:
require 'vendor/autoload.php';
define('FACEBOOK_SDK_V4_SRC_DIR', '/vendor/facebook/php-sdk-v4/src/Facebook/');
define("FACEBOOK_CONSUMER_KEY", "{myKey}");
define("FACEBOOK_CONSUMER_SECRET", "{mySecret}");
define("FACEBOOK_ACCESS_KEY", "{myToken}");
Facebook\FacebookSession::setDefaultApplication(FACEBOOK_CONSUMER_KEY, FACEBOOK_CONSUMER_SECRET);
$session = new Facebook\FacebookSession(FACEBOOK_ACCESS_KEY);
$message = array(
"message" => "It works!",
"link" => "http://www.google.de",
//"picture" => "url to picture",
//"name" => "Picture title",
//"description" => "Description",
);
$response = ( new Facebook\FacebookRequest( $session, 'POST', '/{myPageId}/feed', $message ) )->execute()->getGraphObject();
echo $response->getProperty('id');
Unfortunately I get the following error evertime I execute it:
PHP Fatal error: Uncaught exception 'Facebook\FacebookPermissionException' with message '(#200) The user hasn't authorized the application to perform this action' in {myPath}/FacebookRequestException.php:128
Stack trace:
#0 {myPath}/FacebookRequest.php(280): Facebook\FacebookRequestException::create('{"error":{"mess...', Object(stdClass), 403)
#1 {myPath}/test.php(21): Facebook\FacebookRequest->execute()
#2 {main}
thrown in {myPath}/FacebookRequestException.php on line 128
How can I setup the Facebook App that it work correctly?
You have to do the login flow to authorize your app first. https://developers.facebook.com/docs/php/howto/example_facebook_login/4.0.0
Right now i am working on spotify api, When i hit url for first time it is giving me all playlist but when i refresh page again it is giving me exception error, here is my code,
require '../../../vendor/autoload.php';
$session = new SpotifyWebAPI\Session('******', '*******', 'http://localhost:8080/spotify/vendor/jwilsson/spotify-web-api-php/demo.php');
$api = new SpotifyWebAPI\SpotifyWebAPI();
if (isset($_GET['code'])) {
$session->requestAccessToken($_GET['code']);
$data = $api->setAccessToken($session->getAccessToken());
$artistData = $api->me();
$artistId = $artistData->id;
$playlists = $api->getUserPlaylists($artistId, array(
'limit' => 5
));
foreach ($playlists->items as $playlist) {
echo '' . $playlist->name . ' <br>';
}
} else {
$scopes = array(
'scope' => array(
'user-read-email',
'user-library-modify',
),
);
header('Location: ' . $session->getAuthorizeUrl($scopes));
}
Here is my exception error
Fatal error: Uncaught exception 'SpotifyWebAPI\SpotifyWebAPIException' with message 'Invalid authorization code' in D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Request.php:156 Stack trace: #0 D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Request.php(26): SpotifyWebAPI\Request->send('POST', 'https://account...', Array, Array) #1 D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Session.php(233): SpotifyWebAPI\Request->account('POST', '/api/token', Array) #2 D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\demo.php(31): SpotifyWebAPI\Session->requestAccessToken('AQAaVZvpXUExKg2...') #3 {main} thrown in D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 156
Can anyone please tell me why it cause error ? If anyone have experiance with spotify
Creator of the library here.
The only thing I can think of which would yield that error message is if you try to request a access token twice with the same code. Try visiting the URL to your PHP file again but remove any ?code=... parts.
So I am trying to fetch images posted with a certain hashtag in facebook. I am using the facebook php api. This is my code:
FacebookSession::setDefaultApplication('my-api-key', 'secret');
$session=FacebookSession::newAppSession();
try {
$session->validate();
} catch (FacebookRequestException $ex) {
var_dump($ex);
echo $ex->getMessage();
} catch (\Exception $ex) {
// Graph API returned info, but it may mismatch the current app or have expired.
echo $ex->getMessage();
}
$request = new FacebookRequest(
$session,
'GET',
'/gatos'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
var_dump($graphObject);
I know that the request I am executing is not for pulling hashtags, but anyways, I am getting the following error:
Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message 'Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api' in /var/www/experiments/gatopull/vendor/facebook/php-sdk-v4/src/Facebook/FacebookRequestException.php:104 Stack trace: #0 /var/www/experiments/gatopull/vendor/facebook/php-sdk-v4/src/Facebook/FacebookRequest.php(280): Facebook\FacebookRequestException::create('{"error":{"mess...', Object(stdClass), 400) #1 /var/www/experiments/gatopull/config/facebook_api.php(36): Facebook\FacebookRequest->execute() #2 /var/www/experiments/gatopull/config/apicontroller.php(2): require_once('/var/www/experi...') #3 /var/www/experiments/gatopull/index.php(3): require_once('/var/www/experi...') #4 {main} thrown in /var/www/experiments/gatopull/vendor/facebook/php-sdk-v4/src/Facebook/FacebookRequestException.php on line 104
My questions are:
Do I need a user access-token to search hashtags, or is it
sufficient with the client token?
I know the request I need to do with curl or by url, but how do I make this request with the fb api? Here is the url request:
https://graph.facebook.com/search?q=hashtag&type=post&limit=999&access_token=myaccesstoken
Is there any php library to do this with more social networks?
thanks!
I am using the new version 2, sdk 4.0 php. I am trying to send a notification to a user with my app. I just realised the access token that I get via login (user access token) is different to the access token for my app. I have searched online before posting it on here, but most is for the old sdk and cannot get the right syntax to work with mine.
My code:
$notification = (new FacebookRequest(
$session,
'POST',
'/'.$id[0].'/notifications',
array (
'href' => "http://localhost/app/index.php",
'template' => 'You have been tagged, please set privacy preference',
)
))->execute()->getGraphObject()->asArray();
And my error:
Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message '(#15) This method must be called with an app access_token.' in C:\xampp\htdocs\app\Facebook\FacebookRequestException.php:134 Stack trace: #0 C:\xampp\htdocs\app\Facebook\FacebookRequest.php(268): Facebook\FacebookRequestException::create('{"error":{"mess...', Object(stdClass), 400) #1 C:\xampp\htdocs\app\privacy.php(121): Facebook\FacebookRequest->execute() #2 {main} thrown in C:\xampp\htdocs\app\Facebook\FacebookRequestException.php on line 134
Can someone help me with getting the app access token?
You can get the app access_token as follows:
$appSession = FacebookSession::newAppSession();
Then you can do:
$notification = (new FacebookRequest(
$appSession,
'POST',
'/'.$id[0].'/notifications',
array (
'href' => "http://localhost/app/index.php",
'template' => 'You have been tagged, please set privacy preference',
)
))->execute()->getGraphObject()->asArray();
I have the following code and I'm trying to untag myself in a photo.
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
FacebookSession::setDefaultApplication('<appid>','<appsecret>');
$session = new FacebookSession('<my access token>');
$request = new FacebookRequest(
$session,
'DELETE',
'/<id of photo im tagged in>/tags',
array (
'id' => '<my fb id>',
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
var_dump($response);
var_dump($graphObject);
I have both the permissions user_photos and publish_actions with the access-token that i'm using (as mentioned as required for removing photo tags).
However when I run the above I get this error:
Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message 'Unsupported delete request.'
I've tried to do exactly as in the docs but I can't figure out what I'm doing wrong and why I'm getting this.
What can I do to get it working?
The correct way of deleting a tag is by calling:
$request = new FacebookRequest(
$session,
'DELETE',
'/<id of photo im tagged in>/tags',
array (
'tag_uid' => '<my fb id>',
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
However, this is incorrectly documented. In addition, only whitelisted apps are able to delete tags via the API. The documentation also fails to include this. If you app isn't whitelisted, you will see the following error:
{ "error": {
"message": "(#3) Application does not have the capability to make this API call.",
"type": "OAuthException",
"code": 3 } }