获取" InvalidTokenFormat,错误400"来自Firebase云消息传递

时间:2016-07-30 21:54:26

标签: php android curl firebase firebase-cloud-messaging

我使用Firebase Cloud Messaging作为服务器端语言使用PHP进行Android开发。现在,我能够:

  1. 使用Firebase控制台接收真实应用和模拟器的推送通知。

  2. 从终端(curl)

  3. 测试它时工作正常

    那么,我尝试从apps server(使用php curl)而不是Firebase Console发送。现在,每次我请求POST请求时都会遇到这个奇怪的消息InvalidTokenFormat, Error 400。有什么想法?

    以下是Firebase Api的链接:FirebaseApi Class

    随意请求上述用例的任何输入并不够清楚。感谢。

4 个答案:

答案 0 :(得分:10)

我的错误。网址应该是(最后没有斜线):

 07-30 23:55:24.928 16830-16830/com.lucasmikesoftware.messaround E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lucasmikesoftware.messaround, PID: 16830
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at com.lucasmikesoftware.fuckaround.MyAdapter.setImageListItem(MyAdapter.java:69)
at com.lucasmikesoftware.fuckaround.MyAdapter.getView(MyAdapter.java:42)
at android.widget.AbsListView.obtainView(AbsListView.java:2467)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1270)
at android.widget.ListView.onMeasure(ListView.java:1182)
at android.view.View.measure(View.java:17536)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5478)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17536)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1626)
at android.view.View.measure(View.java:17536)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5478)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17536)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463)
at android.view.View.measure(View.java:17536)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5478)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:671)
at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1319)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:736)
at android.view.View.measure(View.java:17536)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1079)
at android.view.View.measure(View.java:17536)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5478)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:17536)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5478)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17536)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5478)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17536)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5478)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17536)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5478)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2629)
at android.view.View.measure(View.java:17536)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2102)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1218)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1435)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1106)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6018)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:792)
at android.view.Choreographer.doCallbacks(Choreographer.java:596)
at android.view.Choreographer.doFrame(Choreographer.java:557

答案 1 :(得分:0)

您需要从服务器向firebase发送请求,并附上通知消息和用户令牌,然后firebase将接受请求,并以通知的形式将消息广播给所有用户(我们提供的令牌) 。

Firebase和设备适用于投票模型,因此只有firebase可以在您的设备上发送通知,您可以使用设备设置您的投票,但谷歌不允许这样做,因为如果每个应用都开始与设备建立投票隧道,它将占用大量资源。

答案 2 :(得分:0)

您可以将原始请求curl发送到服务器吗?通常curl确实提供了打印输出,不确定php版本。

答案 3 :(得分:0)

CURLOPT_POSTFIELDS不需要JSON。如果你想发送一个application / x-www-form-urlencoded请求,请使用http_build_query($ message),或者如果你想发送multipart / form-data请求,直接给它$ message数组。