views:

39

answers:

1

I've tried using both the JavaScript and PHP SDKs, but I can't solve this simple problem.

My FQL looks like:

SELECT count FROM comments_info WHERE xid="..."

When I attempt the request through PHP, I get the following error:

Uncaught Exception: 604: No valid app_id

PHP:

$facebook = new Facebook(array(
    'appId' => '...',
    'secret' => '...',
    'cookie' => true
));
$result = $facebook->api(array(
    'method' => 'fql.query',
    'query' => 'SELECT count FROM comments_info WHERE xid="'.[...].'"'
));

The appId and secret I copied from the application page in the Facebook Developer app.

Similarly, when I use the JS API, as in:

var query = FB.Data.query('SELECT count FROM comments_info WHERE xid="' + [...] + '"');
query.wait(function(rows){});

... I get the same error in the JSONP response:

FB.ApiServer._callbacks.f2ba554518({"error_code":"604","error_msg":"No valid app_id","request_args":[{"key":"access_token","value":"[MY APP ID]|[THE ACTUAL ACCESS TOKEN]"},{"key":"api_key","value":"[MY APP ID, AGAIN]"},{"key":"callback","value":"FB.ApiServer._callbacks.f2ba554518"},{"key":"format","value":"json-strings"},{"key":"method","value":"fql.multiquery"},{"key":"queries","value":"{\"index_comments_info_xid\":\"select xid,count from comments_info where xid=\\\"[...]\\\"\"}"},{"key":"sdk","value":"joey"}]});

I even tried recreating the application several times.

At this point, I've invested more hours than I'd care to admit :) So, if anyone has experience with this problem, I'd be very appreciative — Facebook's documentation is no help at all, and their dev forums are pretty much dead.

A: 

Oops... bit of facepalm. "No valid app_id" doesn't mean my application id is invalid — it means I need to specify an app_id in my FQL query, as indicated on the documentation page.

Here's a working PHP example for getting the comment count:

require_once('facebook.php');
$facebook = new Facebook(array(
    'appId' => '[...]',
    'secret' => '[...]'
));
try {
    $result = $facebook->api(array(
        'method' => 'fql.query',
        'query' => 'SELECT count FROM comments_info WHERE app_id='.$facebook->getAppId().' AND xid="'.[...].'"'
    ));
} catch (FacebookApiException $e) {
    error_log($e);
}
JKS