开发者

PHP API array loop

I'm trying a loop through a Facebook Graph API loop via a foreach loop but I'm getting this error: "PHP Parse error: syntax error, unexpected T_VARIABLE, expecting T_CATCH".

Any thoughts?

Here's the code:

// WRITING FIRST 50 FRIENDS LIKES

$i = 0;
foreach($userfriends[data] as $value) {

if($key == "id"){
    $friend_id = $value;        
}

try {
    $username = $friend_id;
    $uservar = '/'.$username.'/likes?fiel开发者_开发知识库ds=id,category&limit=20';
    $userlikes = $facebook->api($uservar);
}         

//  catch (FacebookApiException $e) {
//  error_log($e);
//  }

$id = $userlikes[$i][id];
$cat = $userlikes[$i][category];

// WRITING FRIEND LIKES TO DATABASE

$sql="INSERT INTO likes (like_id, category, friend_id) VALUES ('$id', '$cat', '$friend_id');";
mysql_query($sql,$con);
mysql_free_result($sql);
$i++;
}


you have your catch commented out and it is expecting catch


You have a try block without catch.

try {
$username = $friend_id;
$uservar = '/'.$username.'/likes?fields=id,category&limit=20';
$userlikes = $facebook->api($uservar);
} catch {

//exception happened
}


you seem to have commented out the "catch" , re-enable it and the parse error would go away.


Your catch block is commented out - either uncomment it or comment out the try as well. Every try must have at least one catch to handle any exceptions thrown inside the try.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜