SimpleGeo DotnetOpenAuth for C#
I have moved simpleGeo sample from VB(langsamu) to C#. This is an amazing feature for my needs but i not abled to fix the OAuth class that i can't initialize correctly to test-it. I haved posted my complete project in this bottom link including sample. The simpleGeo.dll implement base classes to connect and query simpleGeo. Client.cs is the main point to go & implementing ConsumerBase. need and Gmaps key and simpleGeo key easier to get. Can someone help me to fix.
Thanks for your help, Romi.
here VB : http github.com / simplegeo / simplegeo-dotnet
here C# : C# simpleGeo that need your help
namespace SimpleGe开发者_如何学编程o
{
public class Client : DotNetOpenAuth.OAuth.ConsumerBase
{
private SimpleGeo.Description Services;
private SimpleGeo.TokenManager Tokens;
public Client(Version Version, string Key, string Secret): base(new Description(Version), new TokenManager(Key, Secret))
{
//added because not firing Public proprieties of base.
Services = new Description(Version);//remplace Services
Tokens = new TokenManager(Key, Secret);//remplace Token
}
...
public ServiceProviderDescription Service
{
get { return base.ServiceProvider; }
}
private IConsumerTokenManager Token
{
get { return base.TokenManager; }
}
....
Well, I love simplegeo but the guys dont see .NET as a viable API consumer :) - VB sample is pretty much useless and SimpleGeo.NET seems abandoned (?). I decided to roll out my own client for a project I have in mind and since there is an excellent REST library supporting OAuth (RestSharp) I gave it a try with simplegeo. A very rude example follows:
//create client and pass OAuth credentials
RestClient client = new RestClient("http://api.simplegeo.com");
client.Authenticator = OAuth1Authenticator.ForRequestToken(yourapikey, yoursecret);
//sample of creating a request for a specific simplegeo endpoint (places near an IP)
RestRequest request = new RestRequest(Method.GET) {Resource = "{version}/places/{ip}.json", RequestFormat.Json};
request.AddParameter("version", "1.0", ParameterType.UrlSegment);
request.AddParameter("ip", anyiphere, ParameterType.UrlSegment);
//call the api function
RestResponse response = client.Execute(request);
//get the simplegeo response in json
string json = response.Content;
Use Json.NET for deserializing into any custom classes of yours.
You may have a helper class constructing the request for you according to parameters passed - keep version somewhere not hardcoded just in case :)
精彩评论