Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $ #416

Open
mohammed-ezzedine opened this issue Mar 5, 2020 · 4 comments

Comments

@mohammed-ezzedine
Copy link

mohammed-ezzedine commented Mar 5, 2020

Issue Summary

Getting the error:

Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $

Here's my code:

public void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "onCreate");
        super.onCreate(savedInstanceState);
        final Video video = VideoPlayActivity.video;

        TestApp d = new TestApp();
        d.onCreate();
        mApiClient = d.getmApiClient();

        String uri = video.getVideoUri().toString();
        mApiClient.getInstance().fetchNetworkContent(uri, new ModelCallback<Video>(Video.class) {
            @Override
            public void success(Video video) {
                Log.i(TAG, "get success.");
                // use the video
            }

            @Override
            public void failure(VimeoError error) {
                Log.i(TAG, error.getErrorMessage());
                // voice the error
            }
        });
}

And these are the important methods in TestApp:

public class TestApp extends Application {
@Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "onCreate");

        sContext = this;

        Configuration.Builder configBuilder = getClientIdAndClientSecretBuilder();
        VimeoClient.initialize(configBuilder.build());
        mApiClient = VimeoClient.getInstance();
    }
    
    public Configuration.Builder getClientIdAndClientSecretBuilder() {
        String clientId = "dc62dc72e8c7cf4d0b7bb025d41e2a7649ddc0a4";
        String clientSecret = "SRbzt7mLfbA0l5aEV8lXINE54nRGkSp8S2i+wOp9paOqQsEKkwC5MtdwFPHiVqX7DTCooPVWAxPVjG8/pjjPbl+7LNTXTuSDit1oZGtCjkBYFqahb95J4pAHzEumdNhs";
        return new Configuration.Builder(clientId, clientSecret, SCOPE);
    }
}
@mohammed-ezzedine mohammed-ezzedine changed the title java.lang.AssertionError: Instance must be configured before use Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $ Mar 6, 2020
@rvanderlinden
Copy link

rvanderlinden commented May 11, 2020

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}.")
                }
            })

@rvanderlinden
Copy link

rvanderlinden commented May 12, 2020

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?) {
                }
            })

@iganinja
Copy link

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 = "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.

@rvanderlinden
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants