我试图使用毕加索加载从谷歌图书查询的图像 URL,但我似乎得到了意想不到的结果。这是我的意思的一个例子:
当我在浏览器中访问此 URL时,它会返回此 JSON 文件作为第一个结果:
{
"kind": "books#volumes",
"totalItems": 4,
"items": [
{
"kind": "books#volume",
"id": "4qcADQAAQBAJ",
"etag": "c5anSfOihZE",
"selfLink": "https://www.googleapis.com/books/v1/volumes/4qcADQAAQBAJ",
"volumeInfo": {
"title": "The Obsession: By Nora Roberts (Trivia-On-Books)",
"authors": [
"Trivion Books"
],
"publishedDate": "2016-09-08",
"description": "Trivia-on-Book: The Obsession by Nora Roberts Take the challenge yourself and share it with friends and family for a time of fun! Nora Roberts is back with her latest novel, The Obsession. From an author whose works have spent over a thousand weeks on the bestseller list, it is almost criminal to expect anything but absolute brilliance. Roberts does not disappoint in this fast-paced tale of a young girl who witnesses her father’s barbarism and how one fateful night changes her life forever. Roberts has come up with another masterpiece in the romantic thriller genre. The Obsession became yet another Nora Roberts novel that reached The New York Times number one spot. You may have read the book, but not have liked it. You may have liked the book, but not be a fan. You may call yourself a fan, but few truly are. Are you a fan? Trivia-on-Books is an independently curated trivia quiz on the book for readers, students, and fans alike. Whether you're looking for new materials to the book or would like to take the challenge yourself and share it with your friends and family for a time of fun, Trivia-on-Books provides a unique approach to The Obsession by Nora Roberts that is both insightful and educational! Features You'll Find Inside: • 30 Multiple choice questions on the book, plots, characters and author • Insightful commentary to answer every question • Complementary quiz material for yourself or your reading group • Results provided with scores to determine \"status\" Promising quality and value, come play your trivia of a favorite book!",
"readingModes": {
"text": true,
"image": true
},
"printType": "BOOK",
"categories": [
"Study Aids"
],
"maturityRating": "NOT_MATURE",
"allowAnonLogging": false,
"contentVersion": "1.1.1.0.preview.3",
"panelizationSummary": {
"containsEpubBubbles": false,
"containsImageBubbles": false
},
"imageLinks": {
"smallThumbnail": "http://books.google.com/books/content?id=4qcADQAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api",
"thumbnail": "http://books.google.com/books/content?id=4qcADQAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
},
"language": "en",
"previewLink": "http://books.google.com/books?id=4qcADQAAQBAJ&printsec=frontcover&dq=intitle:The+Obsession:+By+Nora+Roberts+(Trivia-On-Books)&hl=&cd=1&source=gbs_api",
"infoLink": "http://books.google.com/books?id=4qcADQAAQBAJ&dq=intitle:The+Obsession:+By+Nora+Roberts+(Trivia-On-Books)&hl=&source=gbs_api",
"canonicalVolumeLink": "https://books.google.com/books/about/The_Obsession_By_Nora_Roberts_Trivia_On.html?hl=&id=4qcADQAAQBAJ"
},
"saleInfo": {
"country": "LK",
"saleability": "NOT_FOR_SALE",
"isEbook": false
},
"accessInfo": {
"country": "LK",
"viewability": "PARTIAL",
"embeddable": true,
"publicDomain": false,
"textToSpeechPermission": "ALLOWED",
"epub": {
"isAvailable": true,
"acsTokenLink": "http://books.google.com/books/download/The_Obsession_By_Nora_Roberts_Trivia_On-sample-epub.acsm?id=4qcADQAAQBAJ&format=epub&output=acs4_fulfillment_token&dl_type=sample&source=gbs_api"
},
"pdf": {
"isAvailable": true,
"acsTokenLink": "http://books.google.com/books/download/The_Obsession_By_Nora_Roberts_Trivia_On-sample-pdf.acsm?id=4qcADQAAQBAJ&format=pdf&output=acs4_fulfillment_token&dl_type=sample&source=gbs_api"
},
"webReaderLink": "http://play.google.com/books/reader?id=4qcADQAAQBAJ&hl=&printsec=frontcover&source=gbs_api",
"accessViewStatus": "SAMPLE",
"quoteSharingAllowed": false
},
"searchInfo": {
"textSnippet": "The Obsession became yet another Nora Roberts novel that reached The New York Times number one spot. You may have read the book, but not have liked it. You may have liked the book, but not be a fan."
}
},
// ...
当我在浏览器中访问thumbnail
or URL 时,它会从这里smallThumbnail
显示本书的正确缩略图,但是当我从这段代码中执行相同的操作时:(在 Kotlin 的 Android Studio 中)。
我没有在这里包含所有内容,但基本上,它请求数据并创建将数据添加到帮助程序和 RecyclerView(我只是将 catch 语句留空并且代码工作正常,问题在于返回的数据)。
private fun getBookData(act: FragmentActivity) {
val data = ArrayList<bookhelper>()
var mRequestQueue = Volley.newRequestQueue(activity)
mRequestQueue.getCache().clear()
// THE same url as above
val url = "https://www.googleapis.com/books/v1/volumes?q=intitle:The%20Obsession:%20By%20Nora%20Roberts%20(Trivia-On-Books)"
val queue: RequestQueue = Volley.newRequestQueue(activity)
val jsonObjectRequest = JsonObjectRequest(Request.Method.GET, url, null,
{response ->
try {
val itemsArray: JSONArray = response.getJSONArray("items")
for (i in 0 until itemsArray.length()) {
val itemsObj: JSONObject = itemsArray.getJSONObject(i)
val volumeObj: JSONObject = itemsObj.getJSONObject("volumeInfo")
val imageLinks = volumeObj.optJSONObject("imageLinks")
val coverimage: String = imageLinks.optString("Thumbnail")
// ...
}
}
} finally {
`is`?.close()
}
}
} catch (e: JSONException) {
e.printStackTrace()
}
},
{ error ->
TODO("")
}
)
queue.add(jsonObjectRequest)
}
//...
并将图像设置为 ImageLayout :
Picasso.get().load(bookhelper.getCoverImageurl()).into(holder.image);
我使用其他一些像这样的随机图像 URL 对此进行了测试,并且效果很好。
并且绝对没有问题,size/scale/pixelation
因为有许多相同类型的函数的工作示例(请参阅本教程和教程底部的输出)。
毕加索返回一个URL must be specified
错误,我记录了返回imageLink
:
Log.e("error", "h ${imageLinks.toString()}")
JSON 对象,这是每个查询返回的内容:
"smallThumbnail":"http:\/\/books.google.com\/books\/content?id=kDooEAAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api","thumbnail":"http:\/\/books.google.com\/books\/content?id=kDooEAAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
访问这些图像 URL 中的每一个都会给出类似于错误页面的内容:
'404 在此服务器上找不到此链接'
我什至尝试只使用浏览器中返回的 JSON 文件中的图像 URL:
Picasso.get().load(http://books.google.com/books/content?id=4qcADQAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api).into(holder.image);
但是,它什么也没做。