Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to call Google's fusionTableAPI with Service account from my C#.net code. I have access token from google, now I need to call the FusionTableAPI to delete a particular row from my fusion Table. I use the following code to do the same but got (401) Unauthorized error.

What I have tried:

string query = "delete from myfusiontable where ROWID = 1"
string sdata = "sql=" + HttpUtility.UrlEncode(query);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(sdata);

// Create the request, encode the query in the body of the post
HttpWebRequest req = (HttpWebRequest)
WebRequest.Create("https://www.googleapis.com/fusiontables/v2/query");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = data.Length;

// Add the authentication header
req.Headers.Add("Authorization: " + access_token);
var t = req.Headers.AllKeys;

Stream sout = req.GetRequestStream();
sout.Write(data, 0, data.Length);
sout.Close();
try
{
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader stIn = new StreamReader(res.GetResponseStream());
return stIn.ReadToEnd();
}
catch (WebException e)
{
StreamReader stIn = new StreamReader(e.Response.GetResponseStream());
return stIn.ReadToEnd();
}



I do lot of R&D but didn't got the solution.Is there anything which I could have missed out? Any help would be greatly appreciated.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900