Graph API: 2.4
PHP SDK: "facebook/php-sdk-v4": "~5.0"
I'd like to get details about a page via PHP and the PHP SDK.
Using the query:
$response = $fb->get('/' . $sPageID . '?fields=posts', $_SESSION['facebook_access_token']);
returns the posts with a good amount of data. But unfortunately wrong values:
The limit 25 for likes for instance applies here. So even if one post should have 150 likes, if I do an count ($post['likes']) I only get 25 as a result.
So I tried to change my query and according to the Graph Explorer
this seems to be working fine:
PAGE_ID/posts?fields=likes.limit(100),message,comments,shares,picture,link,type
Now I can't get this transformed into my PHP call.
I receive timeouts and
Fatal error: Uncaught exception 'Facebook\Exceptions\FacebookSDKException' with message 'Unable to convert response from Graph to a GraphNode because the response looks like a GraphEdge. Try using GraphNodeFactory::makeGraphEdge() instead.' in ...
Is this possible with one query in PHP or do I have to run multiple queries, one for each post?
I found this answer, and if because the end of point of this request is a GraphEdge, so try this:
// Get basic info on the user from Facebook.
try {
$response = $fb->get('/' . $sPageID . '?fields=posts', $_SESSION['facebook_access_token']);
} catch (Facebook\Exceptions\FacebookSDKException $e) {
dd($e->getMessage());
}
$getGraphEdge = $response->getGraphEdge();
I hope this help you.
Regards.
Newer PHP SDK versions have the getGraphList() method, getGraphEdge() is for the earlier, even though it wasn't documented.
Related
I am using the PayPal PHP SDK found here: https://github.com/paypal/Checkout-PHP-SDK
And I am somewhat puzzled in terms of how to complete the process.
On the outset this seems quite simple:
Setup your credentials
Create the Order
Check the result, and re-direct to approval link
User makes a payment and is sent to the SUCCESS link that you would have set.
i.e. http://example.com/pay/complete/paypal?token=8UK32254ES097084V&PayerID=SEQNPLB2JR9LY
And this is where things get a bit shakey.
Conveniently, a token and a PayerID is returned.
And according to the documentation, you now need to "Capturing the Order" and the following code is provided:
use PayPalCheckoutSdk\Orders\OrdersCaptureRequest;
// Here, OrdersCaptureRequest() creates a POST request to /v2/checkout/orders
// $response->result->id gives the orderId of the order created above
$request = new OrdersCaptureRequest("APPROVED-ORDER-ID");
$request->prefer('return=representation');
try {
// Call API with your client and get a response for your call
$response = $client->execute($request);
// If call returns body in response, you can get the deserialized version from the result attribute of the response
print_r($response);
}catch (HttpException $ex) {
echo $ex->statusCode;
print_r($ex->getMessage());
}
What is confusing is that the OrdersCaptureRequest requires an "APPROVED-ORDER-ID"
But all that has been returned is a "token" and a "PayerID".
So my question is, what is this APPROVED-ORDER-ID, and where do I get it?
Thank you!
what is this APPROVED-ORDER-ID, and where do I get it
At that moment, sourced from token= . It should correspond to an Order Id you received in the response to your step 2 ("Create the Order")
For step 3, it is better to use no redirects whatsoever. Instead, implement this front-end UI, which offers a far superior in-context experience that keeps your site loaded in the background: https://developer.paypal.com/demo/checkout/#/pattern/server
There is no reason for a modern website to be redirecting unnecessarily
I am using this solution to select an individual post from a user's feed.
I am using PHP Facebook SDK on the latest version 5.7.
Previously this had worked with no problem, I made my request like:
$response = $this->fb->get(
'/'.$user['id']. '_' .$post_id.'/?fields=id,description,name,full_picture',
$this->get_access_token()
);
And I would get all the fields. However, over the last few months, this has stopped working.
The access_token requests the following permissions:
['user_events', 'user_posts']
I can't find any documentation on the solution outlined in the Stack Overflow post. So I am not sure if I need any more permissions.
I do not get an error when sending this request, I just get the ID back and nothing else. This can be confirmed in the Graph API Explorer:
The v5.0 docs show that when requesting a post I can get full_picture, name and description without mentioning any additional permissions required.
However that same page recommends making the request with just the post ID:
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/{post-id}',
'{access-token}'
);
}
Which does not work, you
{
"error": {
"message": "(#12) singular statuses API is deprecated for versions v2.4 and higher",
"type": "OAuthException",
"code": 12,
"fbtrace_id": "ACs2rpwobcW8zSFyL_0Q2yQ"
}
}
The error does mention statuses and not posts but I am not sure how to distinguish the difference between those, I figured they were the same.
Has anyone else stumbled across this and found a solution?
It turns out that the fact it was called status was important. I made a request to the users feed, and noticed that some older posts were returning the data that I needed. I had a look through the list of fields and appended message and type to get the following response:
Not very well documented I guess. But got there in the end, hopefully this can help someone else in future.
I'm having a strange problem with the Facebook PHP SDK,
$response = $this->getConnection()->get("me/posts");
$feedEdge = $response->getGraphEdge();
var_dump($response); exit;
the getConnection() call provides me with a \Facebook\Facebook object with the default_access_token set but this works as I get a response from Facebook
But the body from the above var_dump gives:
["decodedBody":protected]=>
array(1) {
["data"]=>
array(0) {
}
}
What is really strange is when I use the Graph Explorer (as my Application and using the same Page) I see all the posts. So I thought maybe it was the access token was not working correctly so I copied and pasted the access token shown in from the graph explorer into my get() call to override the default like below unfortunately this did not work and I got exactly the same output.
$response = $this->getConnection()->get("me/posts", "EAA....");
$feedEdge = $response->getGraphEdge();
var_dump($response); exit;
So I'm unsure why the same token in one place would get the information when in another it would get an empty set the worst part is it's not like the Request is failing as that throws an exception it is like Facebook Graph API is reacting differently for my application when using the PHP-SDK verses using the Explorer.
So after hours of messing around testing stuff in the Graph API Explorer and the API I worked out, there is a problem with /me/posts endpoint when using the PHP SDK even if your using a manage_pages access_token it seems to lock on to the user that instead of the page unlike the graph explorer that the /me/posts, posts to the entity of the access_token.
So make sure to request /{page_id|user_id}/posts and it works correctly.
I have a problem with Updating and Deleting events using signed requests. Inserting events works just fine. But when Updating and Deleting I receive an "Unknown authorization header" 401 error.
For ALL three operations I first generate the client like this:
$client = new Zend_Gdata_HttpClient();
$client->setAuthSubPrivateKeyFile('certificates/gcalkey.pem', null, true);
$client->setAuthSubToken($session_token);
$gdataCal = new Zend_Gdata_Calendar($client);
To Update an event I use this:
$eventOld = $gdataCal->getCalendarEventEntry($eventUri);
$eventOld->title = $gdataCal->newTitle('NEW NAME');
try {
$eventOld->save();
} catch (Zend_Gdata_App_Exception $e) { print_r($e); exit; }
And it gives me the "Unknown authorization header" error. But the same code, using unsigned requests, works.
Where might be the problem? I tried modifying $eventUri to both https and http, but it seems it does not have any effect.
I've been getting this 401 error message too, creating the client and service the same way. It can retrieve a list of calendars, but fails when retrieving an event feed.
Has this worked for you before? It might not be officially supported yet.
Hi I m trying to create application in facebook but I m getting error as api call in facebook is not working properly. I m using following code:
try {
$uid = $facebook->getUser();
$fbme = $facebook->api('/me');
} catch (FacebookApiException $e) {
echo "uid: $uid<br>";
var_dump($fbme);
echo $e;
}
In this I get uid but $fbme is NULL. The error returned is CurlException: 6: name lookup timed out.
Why this is happening??
Pls help me.
It is interesting to note that the PHP
SDK will make the old REST API call to
different Facebook's server based on
whether the API call is a
"READ_ONLY_CALL" or not. For
"READ_ONLY_CALL" requests, they will
be passed to "api-read.facebook.com".
Otherwise, the request will be passed
to "api.facebook.com".
While I have no control on how the
name lookup is done on the web server
(as I am using web host services), I
have tried to amend facebook.php by
renaming "api-read.facebook.com" to
"api.facebook.com". Well, the name
lookup problem is resolved.
Looking at Facebook's bug tracking
system reveals the fact that I am not
the only one who have encountered
this. So, you may want to apply the
same "workaround" if you encounter the
same problem.
http://www.takwing.idv.hk/tech/fb_dev/phpsdk/learning_phpsdk_07.html
I had this same problem when developing locally on a virtual machine. I solved it by upping my Curl Connect Timeout.
Look for CURLOPT_CONNECTTIMEOUT = 10 in your facebook SDK. Try changing it to CURLOPT_CONNECTTIMEOUT = 30 or CURLOPT_CONNECTTIMEOUT = 60
Facebook has a continuous habit of changing its API methods and call techniques. Developers face a lot of problem for this. Recently they changed their version to 3.0.0. But for the above code, there is some error with your coding technique. You can match your code with this one and see what is wrong. as i have left Facebook programming, i can directly help you in the code. sorry.