php-firebase-cloud-messaging icon indicating copy to clipboard operation
php-firebase-cloud-messaging copied to clipboard

how can I unsubscribeFromTopic

Open yuzimian opened this issue 7 years ago • 8 comments

yuzimian avatar Sep 08 '18 06:09 yuzimian

By having the token you would like to unsubscribe from the topic you could do this:

use sngrl\PhpFirebaseCloudMessaging\Client;

$server_key = '_YOUR_SERVER_KEY_';
$client = new Client();
$client->setApiKey($server_key);
$client->injectGuzzleHttpClient(new \GuzzleHttp\Client());

$response = $client->removeTopicSubscription('_YOUR_TOPIC_ID_', ['_YOUR_TOKEN_']);

redjanym avatar Sep 09 '18 12:09 redjanym

I try this give me error INVALID_ARGUMENT , and TopicID is right and working right when I sent to it and Token is right when I send to it but when I try to unsubscribe give me this error

A7medMarzouk1 avatar Nov 28 '18 02:11 A7medMarzouk1

Can you post here a sample of the code you use?

redjanym avatar Nov 28 '18 10:11 redjanym

@redjanym

I used the code on yr documentation here

use sngrl\PhpFirebaseCloudMessaging\Client;

$server_key = 'YOUR_SERVER_KEY'; $client = new Client(); $client->setApiKey($server_key); $client->injectGuzzleHttpClient(new \GuzzleHttp\Client()); $unwanted_token = "Token THat I want to delete from Topic"; $topic_name ="TopicName"; $response = $client->removeTopicSubscription($topic_name, [$unwanted_token]); var_dump($response->getStatusCode()); var_dump($response->getBody()->getContents()); // this give me error Invalid registration id

and when I sent push notification from firebase console to this unwanted_token , I get the notification , and When I send push to TopicName , I get push notification , so I don't know what's error on the package

A7medMarzouk1 avatar Nov 28 '18 19:11 A7medMarzouk1

Does this happen with a single Token or also with other tokens on that Topic?

redjanym avatar Nov 29 '18 08:11 redjanym

I tried it with single token ,what's the difference it's array right ?? if you want , I can try it with 2 tokens in the array and send you the result

A7medMarzouk1 avatar Nov 29 '18 09:11 A7medMarzouk1

I'm trying to understand if this issue is with that particular token or with all tokens Firebase generates. Try it again with the second token and see what result do you get. This error is caused when the token is not valid.

redjanym avatar Nov 29 '18 13:11 redjanym

I tried the token on firebase console , it works , and tried to send to individual tokens works too ,

so I don't know what the wrong with it , I will try again and feedback

A7medMarzouk1 avatar Nov 29 '18 13:11 A7medMarzouk1