This project has moved and is read-only. For the latest updates, please go here.
2

Closed

POST to graph + Json Encoding doesn't do what it "should"

description

I'm using the ads api through graph. Just transferred over. We build up an elaborate set of ExpandoObjects to post the ad. One of the sub-ExpandoObjects is called "creative" and it has the creative. The JSON encoding that's happening in here seems to be brain damaged about escaping double quotes. Here's a part of the posted form grabbed from the stream. Note the "body" text has double quotes in it and whatever JSON encoding is happening inside the FacebookSDK seems to be falling down here:


Content-Disposition: form-data; name="creative"

{"title":"Put your quarters up!","body":"Please "check" out the classics at the coinop.org museum.","image_file":"@image_7036.png","type":27,"story_id":"266129693418752_286263474731831","object_id":266129693418752,"name":"Dynamic 1_polybius.aspx_Arcade Games"}
--8ce614f4e9a4932



this is the function we have to do the post:
    public static dynamic GraphPost(string url, IDictionary<string, object> postData)
    {
        var app = new Facebook.FacebookClient();
        dynamic result = app.Post(url, postData);
        return result;
    }
the url is:

https://graph.facebook.com/act___________/adgroups?access_token=______

So it has the proper token, etc.

Any ideas on why that's happening? I don't want to write checks for double quote handling if this is a bug in the FacebookSDK, which at the moment I think is true.

thanks
Closed Feb 6, 2012 at 8:34 PM by ntotten

comments

prabirshrestha wrote Oct 26, 2011 at 11:51 AM

could you paste the full code at how you are creating the parameters with the ExpandoObject.
It most likely you are setting the FacebookMediaObject in the wrong way.

Minimalist360 wrote Nov 11, 2011 at 4:09 AM

sure, but the double quote error is jsut in a regular property:

{"title":"Put your quarters up!","body":"Please "check" out the classics at the coinop.org museum."


the quotes around "check" are not escaped and this results in invalid json. I have a manual quote escape hac kin here now.
       dynamic adgroup_specs= new ExpandoObject();

       dynamic creative = new ExpandoObject();
       creative.title = adtitle;
       creative.body = adbody;

        if (ad.FbCampaignUploadInfo.Image != null && ad.FbCampaignUploadInfo.Image.ImageId != 0)
        {
             creative.image_file = "@image_" + ad.FbCampaignUploadInfo.Image.ImageId + ".png";
             var fmo = new Facebook.FacebookMediaObject { FileName = adgroup_specs.creative.image_file, ContentType = "image/png" };
            fmo.SetValue(adg_dc.Images.Where(r => r.ImageId == ad.FbCampaignUploadInfo.Image.ImageId).First().ImageData);
            ((IDictionary<string, object>)adgroup_specs).Add(fmo.FileName, fmo);
        }

        adgroup_specs.creative = creative;
The adgroup_specs has other properties etc added in here, then goes through some sub-methods that do things like create and append a token to the url, and then gets passed in here as postdata:
    public static dynamic GraphPost(string url, IDictionary<string, object> postData)
    {
        var app = new Facebook.FacebookClient();
        dynamic result = app.Post(url, postData);
        return result;
    }

The json I originally posted was grabbed from the wire via fiddler2 and it errors out at facebook. I've added code to escape double quotes manually in the interim.

Minimalist360 wrote Nov 11, 2011 at 4:11 AM

PS the media gets uploaded fine with the quote hack in, replacing " with \" inside adtitle and adcopy. looks correct on the wire, and facebook accepts it fine.

prabirshrestha wrote Nov 11, 2011 at 4:53 AM

bug confirmed

prabirshrestha wrote Nov 11, 2011 at 5:18 AM

seems like it is a bug in SimpleJson.EscapeToJavascriptString. I have already patched it and pushed the changes.

could you download the latest version and give it a try. http://facebooksdk.codeplex.com/SourceControl/changeset/changes/3923a193ca45
let us know if it works as expected.

prabirshrestha wrote Feb 12, 2012 at 3:05 AM

there has been a major rewrite in v6 on how we encode.
please download the latest version from github and continue the discussion at https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/issues/70

thanks.
prabir