denderp
denderp

Reputation: 95

FacebookClient GetTaskAsync sometimes returns invalid JSON string(UWP 10)

i'm trying to get data from Facebook using the FacebookClient API. However i sometimes get the error "Invalid JSON string". The strange thing is that sometimes i do get data using the same task.

this is my code

    public async void GetData(String AccessToken, String task)
    {
        FacebookClient fbclient = new FacebookClient(AccessToken);
        try {
            var res = await fbclient.GetTaskAsync(task);//me/feed
            String data = res.ToString();
            /*IDictionary<string, object> o3 = (IDictionary<string, object>)await fbclient.GetTaskAsync(task);
            JsonObject o2 = (JsonObject) await fbclient.GetTaskAsync(task);*/
        }
        catch (Exception e)
        {

        }
    }

var res = ... gives the error. i don't know why it sometimes works and another time it doesn't.

thanks in advance.

Upvotes: 1

Views: 527

Answers (2)

Andrew Au
Andrew Au

Reputation: 101

The SDK recently stopped working in Windows 10 apps (UWP), but continues to work fine in Windows 8.1 apps.

It's been reported on the GitHub page of facebook-csharp-sdk. The cause is UWP's default to the newer HTTP/2 protocol which is causing problems. Unfortunately, there is no fix yet.

UPDATE: There is a temporary solution where if you open Internet Explorer > Internet Options > Advanced > Disable HTTP 1.1 and HTTP 1.1 through proxy, then the SDK will continue to work in UWP runtime. Obviously not a real solution to the problem, but it brings us one step closer to finding the underlying cause.

Upvotes: 2

Nidheesh Puthalath
Nidheesh Puthalath

Reputation: 206

Those who are struggling to find a permanent solution on Windows UWP App integration with Facebook, here is an updated SDK.

In GitHub https://github.com/Microsoft/winsdkfb

In Nuget.org https://www.nuget.org/packages/winsdkfb/

You can either use this Github SDK or download the same from Nuget package.

After login, FBSession object contains Users complete information which can be a replacement of fbclient.GetTaskAsync("me").

Hope this helps

Upvotes: 1

Related Questions