views:

40

answers:

2

I am using the Facebook-c-sharp to upload photos to Facebook. This code works fine but for new accounts of Facebook this code seems to have problem. I thought may be its something to do with the new privacy policies of Facebook and moreover authors of above code have stopped working on new releases. The problem seems to be with creating albums. With old account of FB, the album gets created and photos are uploaded properly. For new account(created recently, about 20 days back), the photo album gets created but when the Facebook returns the XML response, I get an XMLException thrown when I try to deserialize the XML.

The XML response for old account is below

    <?xml version="1.0" encoding="UTF-8"?>
<photos_createAlbum_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd"&gt;
  <aid>2470234845268380151</aid>
  <owner>number</owner>
  <name>AlbumName</name>
  <created>number</created>
  <modified>number</modified>
  <description>description</description>
  <location>location</location>
  <link>url of the album created</link>
  <size>0</size>
  <visible>privacy setting</visible>
  <modified_major>number</modified_major>
  <object_id>number</object_id>
</photos_createAlbum_response>

The xml response for new account is below

    <?xml version="1.0" encoding="UTF-8"?>
<photos_createAlbum_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd"&gt;
  <aid>100001291780378_24994</aid>
  <owner>number</owner>
  <name>AlbumName</name>
  <created>number</created>
  <modified>number</modified>
  <description>description</description>
  <location>location</location>
  <link>url of the album created</link>
  <size>0</size>
  <visible>privacy setting</visible>
  <modified_major>number</modified_major>
  <object_id>number</object_id>
</photos_createAlbum_response>

The XMLException I am getting is below (again:this is happening only for new accounts. old account deserialize works just fine)

type=Mono.Facebook.XMLException

message=Failed parsing XML

stack=
   at Mono.Facebook.Util.GetResponse[T](String method_name, FacebookParam[] parameters)
   at Mono.Facebook.FacebookSession.CreateAlbum(String name, String description, String location)
   at Facebook.PostToFacebook(List`1 photos, String apiKey, String apiSecret, String authToken)



type=System.InvalidOperationException

message=There is an error in XML document (0, 0).

stack=
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)
   at Mono.Facebook.Util.GetResponse[T](String method_name, FacebookParam[] parameters)

As you can see both the XML responses from Facebook for old and new account are similar. But still for new account deserialize fails. Why is this happening? The only difference I could find in both the xml files was the presence of "underscore _" in (albumid) in second XML file. But as far as I know underscore is valid xml and should not be a problem parsing right? Can someone tell why am I getting this error.

EDIT:

I got it working. As mentioned above, underscore was causing the problem. It was quite silly on my part that I did not check that. In C# code aid was declared as long. Since string with underscore cannot be deserialized to long I was getting exception. I copied the xml response from Facebook into a xml file then did xsd Facebook.xml and xsd Facebook.xsd to get Facebook.cs. I compared generated cs file with the one I have and saw that aid was declared as String in generated cs and long in my file.

A: 

While this really doesn't address your question directly, I think the bigger issue here is that you are using a Facebook library that is very old and not maintained. I would highly suggestion switch to a new library that supports OAuth, the Graph API, and the Rest API. Here is the one that I created and would recommend: http://facebooksdk.codeplex.com

Nathan Totten
will sure have a look at that. Thanks
A: 

I got it working. As mentioned above, underscore was causing the problem. It was quite silly on my part that I did not check that. In C# code aid was declared as long. Since string with underscore cannot be deserialized to long I was getting exception. I copied the xml response from Facebook into a xml file then did xsd Facebook.xml and xsd Facebook.xsd to get Facebook.cs. I compared generated cs file with the one I have and saw that aid was declared as String in generated cs and long in my file.