【问题标题】:Get facebook posts attachments return NullPointerException获取 facebook 帖子附件返回 NullPointerException
【发布时间】:2018-05-28 06:47:58
【问题描述】:

我正在尝试获取页面帖子附件。这是我尝试获取的 JSON:

{
  "attachments": {
    "data": [
      {
        "media": {
          "image": {
            "height": 720,
            "src": "url",
            "width": 720
          }
        }
      }
    ]
  },
  "id": "post_id"
}

我的@GET 请求:

@GET("{post_id}")
fun getPostsAttachments(@Path("post_id") postId : String?,
                        @Query("access_token") authToken: String?,
                        @Query("fields") media : String?)
        :Observable<AttachmentsList>

可观察:

var getPostsAttachments: Observable<AttachmentsList> = facebook.getPostsAttachments(postId, "app_token", "attachments")
        getPostsAttachments.observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribeBy(
                        onNext = { result ->
                        imgUrl?.addAll(result.data)
                        Log.d("TAG_NEXT", "$result")
                    },
                    onError = { throwable -> Log.d("TAG_ERROR", throwable.toString()) },
                    onComplete = { Log.d("TAG_COMPLETE", "$imgUrl") }
                )

它返回D/TAG_NEXT: AttachmentsList(data=null)D/TAG_COMPLETE: null

我该如何解决?也许我的链接请求是错误的?

【问题讨论】:

    标签: android facebook kotlin retrofit rx-java


    【解决方案1】:

    根据我在https://developers.facebook.com/docs/graph-api/reference/v2.11/attachment 上看到的信息,您的通话路径是错误的。尝试将 Retrofit 调用注释更改为 @GET("{post_id}/attachments")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-20
      • 1970-01-01
      • 1970-01-01
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多