I’m implementing the push notification in my application using exponent-server-sdk-php, the implementation on the phone part worked and I can get the token on the server-side however when I do the subscribe with [‘id’, 'ExponentPushToken [ token] '] it returns me an exception that my token is not valid.
StackTrace:
Details
Code: 422
Message: The token provided is not a valid expo push notification token.
File: D:\xampp\htdocs\notification_server\vendor\alymosul\exponent-server-sdk-php\lib\Exceptions\ExpoRegistrarException.php
Line: 14
Trace
#0 D:\xampp\htdocs\notification_server\vendor\alymosul\exponent-server-sdk-php\lib\ExpoRegistrar.php(38): ExponentPhpSDK\Exceptions\ExpoRegistrarException::invalidToken()
#1 D:\xampp\htdocs\notification_server\vendor\alymosul\exponent-server-sdk-php\lib\Expo.php(60): ExponentPhpSDK\ExpoRegistrar->registerInterest(‘892277397f00acc…’, ‘ExponentPushTok…’)
#2 D:\xampp\htdocs\notification_server\vendor\server\src\Model\Token.php(49): ExponentPhpSDK\Expo->subscribe(‘892277397f00acc…’, ‘ExponentPushTok…’)
#3 D:\xampp\htdocs\notification_server\index.php(23): NotificationServer\Model\Token::notify(Object(ExponentPhpSDK\Expo), Array)
#4 [internal function]: {closure}(‘titulo’)
#5 D:\xampp\htdocs\notification_server\vendor\slim\slim\Slim\Router.php(200): call_user_func_array(Object(Closure), Array)
#6 D:\xampp\htdocs\notification_server\vendor\slim\slim\Slim\Slim.php(1210): Slim\Router->dispatch(Object(Slim\Route))
#7 D:\xampp\htdocs\notification_server\vendor\slim\slim\Slim\Middleware\Flash.php(86): Slim\Slim->call()
#8 D:\xampp\htdocs\notification_server\vendor\slim\slim\Slim\Middleware\MethodOverride.php(94): Slim\Middleware\Flash->call()
#9 D:\xampp\htdocs\notification_server\vendor\slim\slim\Slim\Middleware\PrettyExceptions.php(67): Slim\Middleware\MethodOverride->call()
#10 D:\xampp\htdocs\notification_server\vendor\slim\slim\Slim\Slim.php(1159): Slim\Middleware\PrettyExceptions->call()
#11 D:\xampp\htdocs\notification_server\index.php(26): Slim\Slim->run()
#12 {main}
notify() Method:
$interestDetails = [md5(uniqid(rand(), true)), (string) $token];
$expo->subscribe($interestDetails[0], $interestDetails[1]);
$notification = array(
'title' => 'Nova Publicação',
'body' => $postTitle,
'data' => json_encode($data)
);
$expo->notify($interestDetails[0], $notification);
I did not find the problem in my token to be invalid because the test it does with the last string is just this:
private function isValidExpoPushToken(string $token)
{
return substr($token, 0, 18) === 'ExponentPushToken[' && substr($token, -1) === ']';
}
and what I send to subscribe is something like:
ExponentPushToken[mQL4QSOPCzoVaDjVZTqlTZ]