Giter Site home page Giter Site logo

Comments (8)

Demonslay335 avatar Demonslay335 commented on July 26, 2024

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.

sumeetbajaj51 avatar sumeetbajaj51 commented on July 26, 2024

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.

Demonslay335 avatar Demonslay335 commented on July 26, 2024

@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.

sumeetbajaj51 avatar sumeetbajaj51 commented on July 26, 2024

@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;
    }

    /**

    /**

    • 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.

saranyanuraj avatar saranyanuraj commented on July 26, 2024

I have also got this error

from php-firebase-cloud-messaging.

Demonslay335 avatar Demonslay335 commented on July 26, 2024

@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.

koushikch7 avatar koushikch7 commented on July 26, 2024

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.

Demonslay335 avatar Demonslay335 commented on July 26, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.