4 messages in com.googlegroups.google-base-data-api[Google-Base-API] Inserting over the ...| From | Sent On | Attachments |
|---|---|---|
| Sparser | 24 Jul 2008 23:26 | |
| Tom Wilson | 25 Jul 2008 02:01 | |
| Sparser | 25 Jul 2008 09:54 | |
| Eric (Google) | 27 Jul 2008 13:38 |
| Subject: | [Google-Base-API] Inserting over the API through a Proxy![]() |
|---|---|
| From: | Sparser (ben....@gmail.com) |
| Date: | 07/24/2008 11:26:26 PM |
| List: | com.googlegroups.google-base-data-api |
I'm a junior programmer that has been assigned the task of hooking up a website we're modifying to insert into the google base feed.
Some of the issues I've encountered so far:
1) I have no real data, only fake testing data that I couldn't insert without using the API dry-run flag.
2) The website was designed to output an XML document with the feed information but I couldn't find an easy way to upload it programmatically
3) I do not have access to an official account they will be setting up later to perform the feeds, thats legal's job and we don't get them involved until later, so I've been forced to set up this account for testing purposes. Also, I don't have a public URL to provide for a website developer's key, so I'm hoping an installed app key will do the job.
4) This my current biggest issue: I am forced to work within a network and can only establish a connection through a proxy. This has created a ton of problems for me. I have been able to query the snippets feed and get an Auth key without any problems, but the insertion is causing me a lot of problems.
Which brings me to the main point of this post. My current issue is that I haven't figured out a way to successfully send a GBaseEntry object over the stream provided by the IGDataRequest.GetRequestStream() method that appears to be my only method for sending data while utilizing a proxy.
I've never done anything like this before, but I didn't have any issues getting a traditional HTTP POST request to go through with a proxy.
I sincerely appreciate your time, any help you could provide would be a life saver.
Below is a chunk of code that I hobbled together in a blind attempt to get started. Please don't laugh too hard.
Thanks,
Ben
Note* I starred out strings for anonymity, they should have valid values otherwise Note** the proxy is only required while developing in-house, thus the reason for the conditional in the beginning
public string Insert() { string env = System.Configuration.ConfigurationManager.AppSettings["ENV"].ToString(); string key; GBaseService service;
//if you're in house, use temporary account if (string.Compare(env, "dev", true) == 0 || string.Compare(env, "QA", true) == 0) { key = AppLogic.AppConfig("googlebase.apikey.dev"); service = new GBaseService("*******", key); service.setUserCredentials("*******************", "*************");
WebProxy myproxy = new WebProxy("proxy.*********.com", *******); GDataRequestFactory rf = service.RequestFactory as GDataRequestFactory; rf.Proxy = myproxy; rf.Timeout = 45 * 1000;
XmlDocument result = new XmlDocument();
XmlDocument response = new XmlDocument();
foreach (GBaseEntry e in this.getItems()) { Uri itemsFeedUri = new Uri(GBaseUriFactory.Default.ItemsFeedUri.AbsoluteUri + "?dry- run=true");
IGDataRequest igdr = rf.CreateRequest(GDataRequestType.Insert, itemsFeedUri);
UTF8Encoding encoder = new UTF8Encoding(); byte[] bytearray = encoder.GetBytes(e.ToString());
Stream reqStream = igdr.GetRequestStream(); reqStream.Write(bytearray, 0, bytearray.Length);
reqStream.Close();
using (StreamReader sr = new StreamReader(igdr.GetResponseStream(), true)) { result.LoadXml(sr.ReadToEnd()); // Close and clean up the StreamReader sr.Close(); }
response.AppendChild(result.CloneNode(true)); }
} else { key = AppLogic.AppConfig("googlebase.apikey"); service = new GBaseService("*********", key);
service.setUserCredentials(AppLogic.AppConfig("googlebase.username"), AppLogic.AppConfig("googlebase.password")); }
return "Done";
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Base Data API" group.
To post to this group, send email to Goog...@googlegroups.com
To unsubscribe from this group, send email to
Goog...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/Google-Base-data-API?hl=en
-~----------~----~----~----~------~----~------~--~---




