-1

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?fields=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++;
}

4 Answers 4

1

you have your catch commented out and it is expecting catch

Sign up to request clarification or add additional context in comments.

Comments

1

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
}

Comments

0

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

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.