Thuzi / facebook-node-sdk

Modeled from the (Facebook Javascript SDK), now with the facebook-node-sdk you can now easily write the same code and share between your server (nodejs) and the client (Facebook Javascript SDK).
Other
737 stars 250 forks source link

handle JSONPARSE #89

Closed M425 closed 9 years ago

M425 commented 9 years ago

When I use

FB.api('/me/picture' , {type: 'large', access_token: 'xxxxxxx'}, function(res) {
    console.log(res);
}

always returns

{ error: { code: 'JSONPARSE', Error: [SyntaxError: Unexpected token �] } }

(using graph explorer everything work good)

rurri commented 9 years ago

Also get this error. Appears to be line 302: json = JSON.parse(body);

The body in this case of /picture is not a JSON but an image.

body: GIF89a22�����������....

rurri commented 9 years ago

One possible solution to this would be to set 'followRedirect' on the request options to false. This would then retrieve the JSON data about the photo along with a url that could be used to fetch it.

lemortel commented 9 years ago

got the same error and maked me angry. but i finally found the solution, you should set "redirect" to false.

  FB.api('/' + userid + '/picture', {redirect: false, access_token: appToken}, function (res) {
console.log(res);
}

ref: https://developers.facebook.com/docs/graph-api/reference/user/picture

dbilenkin commented 9 years ago

lemortel, you are a life saver! Thanks!

epegzz commented 9 years ago

Thank you @lemortel, was having the exact same issue! :)