Comments (8)
Are you sure you are following the example and setting a GuzzleHttp Client via injectGuzzleHttpClient()
? You have to provide your own client for it to use, otherwise it is default null
.
from php-firebase-cloud-messaging.
is anyone there for this solution i am also getting same problem ?
Fatal error: Uncaught Error: Call to a member function post() on null in /home/magentoo/public_html/vendor/sngrl/php-firebase-cloud-messaging/src/Client.php:62 Stack trace: #0
from php-firebase-cloud-messaging.
@sumeetbajaj51
As I mentioned above, you need to follow the example code and supply the library with your own GuzzelHttp Client.
$client->injectGuzzleHttpClient(new \GuzzleHttp\Client());
If you are still having issues even with including this, please share your code for review.
from php-firebase-cloud-messaging.
@Demonslay335
Here is my file code where i am getting error---
namespace sngrl\PhpFirebaseCloudMessaging;
use GuzzleHttp;
/**
-
@author sngrl
*/
class Client implements ClientInterface
{
const DEFAULT_API_URL = 'https://fcm.googleapis.com/fcm/send';
const DEFAULT_TOPIC_ADD_SUBSCRIPTION_API_URL = 'https://iid.googleapis.com/iid/v1:batchAdd';
const DEFAULT_TOPIC_REMOVE_SUBSCRIPTION_API_URL = 'https://iid.googleapis.com/iid/v1:batchRemove';private $apiKey;
private $proxyApiUrl;
private $guzzleClient;public function injectGuzzleHttpClient(GuzzleHttp\ClientInterface $client)
{
$this->guzzleClient = $client;
}/**
- add your server api key here
- read how to obtain an api key here: https://firebase.google.com/docs/server/setup#prerequisites
- @param string $apiKey
- @return \sngrl\PhpFirebaseCloudMessaging\Client
*/
public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
return $this;
}
/**
- people can overwrite the api url with a proxy server url of their own
- @param string $url
- @return \sngrl\PhpFirebaseCloudMessaging\Client
*/
public function setProxyApiUrl($url)
{
$this->proxyApiUrl = $url;
return $this;
}
/**
-
sends your notification to the google servers and returns a guzzle repsonse object
-
containing their answer.
-
@param Message $message
-
@return \Psr\Http\Message\ResponseInterface
-
@throws \GuzzleHttp\Exception\RequestException
*/
public function send(Message $message)
{return $this->guzzleClient->post(
$this->getApiUrl(),
[
'headers' => [
'Authorization' => sprintf('key=%s', $this->apiKey),
'Content-Type' => 'application/json'
],
'body' => json_encode($message)
]
);
}
/**
- @param integer $topic_id
- @param array|string $recipients_tokens
- @return \Psr\Http\Message\ResponseInterface
*/
public function addTopicSubscription($topic_id, $recipients_tokens)
{
return $this->processTopicSubscription($topic_id, $recipients_tokens, self::DEFAULT_TOPIC_ADD_SUBSCRIPTION_API_URL);
}
/**
- @param integer $topic_id
- @param array|string $recipients_tokens
- @return \Psr\Http\Message\ResponseInterface
*/
public function removeTopicSubscription($topic_id, $recipients_tokens)
{
return $this->processTopicSubscription($topic_id, $recipients_tokens, self::DEFAULT_TOPIC_REMOVE_SUBSCRIPTION_API_URL);
}
/**
-
@param integer $topic_id
-
@param array|string $recipients_tokens
-
@param string $url
-
@return \Psr\Http\Message\ResponseInterface
*/
protected function processTopicSubscription($topic_id, $recipients_tokens, $url)
{
if (!is_array($recipients_tokens))
$recipients_tokens = [$recipients_tokens];return $this->guzzleClient->post(
$url,
[
'headers' => [
'Authorization' => sprintf('key=%s', $this->apiKey),
'Content-Type' => 'application/json'
],
'body' => json_encode([
'to' => '/topics/' . $topic_id,
'registration_tokens' => $recipients_tokens,
])
]
);
}
private function getApiUrl()
{
return isset($this->proxyApiUrl) ? $this->proxyApiUrl : self::DEFAULT_API_URL;
}
}
from php-firebase-cloud-messaging.
I have also got this error
from php-firebase-cloud-messaging.
@shiyasVp
That's the code from this library, that's not helpful in troubleshooting your issue. You need to share the code where you call this library from. You have to use the injectGuzzleHttpClient()
method to inject your own GuzzleHttp\Client
instance.
from php-firebase-cloud-messaging.
Does anyone got solutions for this? its been long since the issue is notified but no relevant action as been taken why?
from php-firebase-cloud-messaging.
@koushikch7
Please post your code. The OP failed to cooperate, thus we could not troubleshoot any further.
As the documentation examples show, you need to inject your own Guzzle instance. If an instance is not injected, it is default null
and thus the crash.
$client->injectGuzzleHttpClient(new \GuzzleHttp\Client());
from php-firebase-cloud-messaging.
Related Issues (20)
- Cannot install php-firebase-cloud-messaging? HOT 1
- time_to_live - how do you set it? HOT 1
- Token Suscripcion not response
- Token problem HOT 4
- Trait 'sngrl\PhpFirebaseCloudMessaging\Client' not found HOT 1
- setSound is not working HOT 2
- How can I add custom cURL options? HOT 2
- IOS Mutable Content
- how can I unsubscribeFromTopic HOT 8
- How to send an Image through notification or data message type? HOT 1
- Stability
- Could not find a version of package matching your minimum-stability (stable). HOT 1
- Background android notification HOT 3
- Token Infos
- Android sound Android O+ HOT 1
- status received success but not received notification on mobile device HOT 1
- Can i schedule and cancel a scheduled push notification?
- how to use fcm_options.link ?
- Deprecated: Return type Message::jsonSerialize() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-firebase-cloud-messaging.