Facebook New PHP SDK For Graph API - Multi Query

邮差的信 提交于 2019-12-21 09:57:29

问题


I'm at my wits end in what the queries parameter value should look like. So to sumbit a multiquery accross the graph API library, the following would be the code method to perform it, as far as I can tell.

$param = array(
 'method' => 'fql.multiquery',
 'queries' => $multiQuery,
 'callback' => '');
$queryresults = $facebook->api($param);

Using this method in the new PHP SDK library from Facebook, has any one made this work? If so can you drop an example on how you build the complete value of the $multiQuery variable?

I've been struggeling with this for a few days and I'm only finding exmaples with the old PHP library.


回答1:


Why is it always after banging your head for days, you ask a question, and 5 minutes later, you come up with the answer your self.

So here was MY lovely experience.

Since in PHP you can use a "/' character to start a text string, I got my self stuck in the flip flopping of the double quote character and single quote character. It dawned on me that the queries defined in a multi query are, duh, wrapped by double quotes.

So lesson learned? If you have a where clause that uses a string value in a multi query, make sure for pete's sake you use SINGLE QUOTES around the string value your filtering on.

BAD BAD - This is what I did. note the double quotes around myvalue and myothervalue. NAUGHTY!

$multiQuery = {
     "query1":"select something from something where somecolumn = "myvalue"",
     "query2":"select something from something where somecolumn = "myothervalue""
     };

GOOD Example - Now look at myvalue and myothervalue.

$multiQuery = {
     "query1":"select something from something where somecolumn = 'myvalue'",
     "query2":"select something from something where somecolumn = 'myothervalue'"
     };

So now I can...

$multiQuery = {
         "query1":"select something from something where somecolumn = 'myvalue'",
         "query2":"select something from something where somecolumn = 'myothervalue'"
         };

$param = array(       
     'method' => 'fql.multiquery',       
     'queries' => $multiQuery,       
     'callback' => '');       
$queryresults = $facebook->api($param);

And if any of you are wondering what is the actual type of the $multiQuery variable is (for newbie like me), it's just a string data type. It's not an array, nothing more nifty than text.




回答2:


Considering an array of node id's with their respective url's as values you'll have

/**
 *A JSON-encoded dictionary of the queries to perform. The array contains a set of key/value pairs.
 *Each key is a query name, which can contain only alphanumeric characters and optional underscores.
 *Each key maps to a value containing a traditional FQL query.
 */
$fql = '{';
foreach ($path as $key1 => $value1) {
    $fql .= '"' . $key1 . '":"SELECT share_count, like_count, comment_count, total_count FROM link_stat WHERE url=\'' . $value1 . '\'",';
}

$fql .= '}';

$param = array(
    'method'   => 'fql.multiquery',
    'queries'  => $fql,
    'callback' => ''
);
try {
    $fqlresult = $facebook->api($param);
} catch (FacebookApiException $e) {
    watchdog('Facebook Query', 'Parsing error on node @node | @error', array('@node' => $key1, '@error' => $e), WATCHDOG_DEBUG); }



回答3:


You can try this:

$multiQuery= array ("query1" => "query #1 goes here","query2" => "query #2 goes here");

$param = array(
 'method' => 'fql.multiquery',
 'queries' => $multiQuery,
 'callback' => '');

$queryresults = $facebook->api($param);


来源:https://stackoverflow.com/questions/4332739/facebook-new-php-sdk-for-graph-api-multi-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!