为了将HTTP V1 API
PHP(不是旧版API)与PHP结合使用,必须使用REST接口。
https://firebase.google.com/docs/cloud-messaging/send-message#top_of_page
我想知道如何获取Auth 2.0访问令牌?
https://firebase.google.com/docs/cloud-messaging/auth-server
由于没有Google API Client Library
PHP(请参见上面的链接中的示例),如何通过REST调用接收Auth 2.0令牌(无需显示PHP代码)?
相关问题:收到此短暂令牌后,如何刷新此令牌?什么是工作流程?
非常感谢!
实际上,有一种适用于PHP的“ Google Api客户端库”,甚至其中两个:
https://github.com/google/google-api-php-client
和
https://github.com/GoogleCloudPlatform/google-cloud-php
一个提供对API的访问,而另一个则不提供,因此值得一看的是,哪个提供了-您可能需要同时使用它们。
在https://github.com/google/google-api-php-client存储库的自述文件中,您可以找到有关如何获取OAuth访问和刷新令牌的说明。
这两个库都在下面与Guzzle一起使用,并提供了一种使用授权中间件来装饰自己的Guzzle HTTP客户端的方法,因此您不必这样做。
因此,如果其中一个库不提供您要访问的API的支持,则可以应用以下代码段中的代码并亲自访问有问题的API(通过Google Api PHP客户端-“直接进行HTTP请求”) :
// create the Google client
$client = new Google_Client();
/**
* Set your method for authentication. Depending on the API, This could be
* directly with an access token, API key, or (recommended) using
* Application Default Credentials.
*/
$client->useApplicationDefaultCredentials();
// returns a Guzzle HTTP Client
$httpClient = $client->authorize();
无耻的插件:我正在https://github.com/kreait/firebase-php维护一个单独的Admin SDK,以访问与Firebase相关的API ,它具有FCM组件,该组件在此处记录:https:// firebase-php。阅读thedocs.io/en/stable/cloud-messaging.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句