php - facebook APP api notifications to all user

111

I can send a notification to all user that access my APP, using userid stored in a table "fbuid", and all works fine.

But if an user remove my APP the code fail and nobody get notification. How can I solve this problem.

$app_id = 'AAAAAAAA';
$app_secret = 'BBBBBBBBBBBBBB';
$app_access_token = $app_id . '|' . $app_secret;
$query = pg_query($dbconn, "SELECT * FROM fbuid;");
while ($row = pg_fetch_row($query)) 
{
     $response = $facebook->api( '/'.$row[1].'/notifications', 'POST', array(
         'template' => 'Nuovo Annuncio Pubblicato FaiceBuy',
         'access_token' => $app_access_token
     )); 
}
92

Answer

Solution:

That means that the code skips due to exception thrown after failing in 1 case. So, you should write your code in try-catch block, just like this-.

while ($row = pg_fetch_row($query)) 
{
     try
     {
           $response = $facebook->api( '/'.$row[1].'/notifications', 'POST', array(
               'template' => 'Nuovo Annuncio Pubblicato FaiceBuy',
               'access_token' => $app_access_token
           ));
           echo '<pre>Post ID: ' . $response ['id'] . '</pre>';
     } 
     catch(FacebookApiException $e) 
     {
         echo $e->getMessage();
     }
}   

People are also looking for solutions to the problem: PHP - Move element in array to second position

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.