Open mohammed-ezzedine opened 4 years ago
I'm experiencing the same issue. Did you manage to resolve this issue @mezdn?
Code:
fun configureVimeoClient(context: Context) {
val configBuilder: Configuration.Builder = Configuration.Builder("MY_ACCESS_TOKEN")
.setCacheDirectory(context.cacheDir)
if(isDebug) {
configBuilder.enableCertPinning(false)
configBuilder.setLogLevel(Vimeo.LogLevel.VERBOSE)
}
VimeoClient.initialize(configBuilder.build())
}
val vimeoUrl = "https://vimeo.com/foo/bar"
VimeoClient.getInstance().fetchNetworkContent(vimeoUrl, object : ModelCallback<Video>(Video::class.java) {
override fun success(video: Video?) {
var foundVideoUrl = false
video?.files?.forEach { videoFile ->
val link = videoFile.getLink()
if(!foundVideoUrl && link != null) {
foundVideoUrl = true
Timber.d("Video url: $link")
}
}
if(!foundVideoUrl) {
Timber.d("Video url not found.")
}
}
override fun failure(error: VimeoError?) {
Timber.d("Vimeo fetch error ${error?.logString}.")
}
})
For anyone else encountering this issue: It is most likely a problem with the url or ModelCallback model-object you are providing. The json issue most likely indicates the response does not match the expected model object.
For my case specifically, "https://vimeo.com/foo/bar" is the web-url for a vimeo video. The api to fetch Video
data is "https://api.vimeo.com/videos/foo". The base api url ("https://api.vimeo.com/") can be found in Vimeo.VIMEO_BASE_URL_STRING
. This means the actual uri to fetch Video
data becomes "videos/foo".
The following code is now working for me:
val scope = "public private video_files"
val isDebug = true
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.level = if (isDebug) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
val configBuilder: Configuration.Builder = Configuration.Builder("MY_CLIENT_ID", "MY_CLIENT_SECRET", scope)
.setBaseUrl(Vimeo.VIMEO_BASE_URL_STRING)
.setAccessToken("MY_ACCESS_TOKEN")
.setGsonDeserializer(GsonDeserializer())
.setCacheDirectory(context.cacheDir)
.addNetworkInterceptor(loggingInterceptor)
if(isDebug) {
configBuilder.enableCertPinning(false)
configBuilder.setLogLevel(Vimeo.LogLevel.VERBOSE)
}
VimeoClient.initialize(configBuilder.build())
val vimeoUrl = "videos/foo"
VimeoClient.getInstance().fetchNetworkContent(vimeoUrl, object : ModelCallback<Video>(Video::class.java) {
override fun success(video: Video?) {
}
override fun failure(error: VimeoError?) {
}
})
For anyone else encountering this issue: It is most likely a problem with the url or ModelCallback model-object you are providing. The json issue most likely indicates the response does not match the expected model object.
For my case specifically, "https://vimeo.com/foo/bar" is the web-url for a vimeo video. The api to fetch
Video
data is "https://api.vimeo.com/videos/foo". The base api url ("https://api.vimeo.com/") can be found inVimeo.VIMEO_BASE_URL_STRING
. This means the actual uri to fetchVideo
data becomes "videos/foo".The following code is now working for me:
val scope = "public private video_files" val isDebug = true val loggingInterceptor = HttpLoggingInterceptor() loggingInterceptor.level = if (isDebug) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE val configBuilder: Configuration.Builder = Configuration.Builder("MY_CLIENT_ID", "MY_CLIENT_SECRET", scope) .setBaseUrl(Vimeo.VIMEO_BASE_URL_STRING) .setAccessToken("MY_ACCESS_TOKEN") .setGsonDeserializer(GsonDeserializer()) .setCacheDirectory(context.cacheDir) .addNetworkInterceptor(loggingInterceptor) if(isDebug) { configBuilder.enableCertPinning(false) configBuilder.setLogLevel(Vimeo.LogLevel.VERBOSE) } VimeoClient.initialize(configBuilder.build())
val vimeoUrl = "video/foo" VimeoClient.getInstance().fetchNetworkContent(vimeoUrl, object : ModelCallback<Video>(Video::class.java) { override fun success(video: Video?) { } override fun failure(error: VimeoError?) { } })
Thank you very much rvanderlinden for your advice, now I have it working like a charm. Just a small typo in the vimeoUrl part:
val vimeoUrl = "video/foo"
it should be "videos/foo" instead of "video/foo". In plural instead of singular.
@iganinja Glad to be of help. Sorry about the missing s, it probably slipped in when converting project-code to example. Edited for future reference.
Issue Summary
Getting the error:
Here's my code:
And these are the important methods in TestApp: