API and C#

116 views
Skip to first unread message

Bjorn

unread,
Sep 1, 2011, 6:06:49 AM9/1/11
to SpotCloud Buyers
Hi,

Does anyone has a sample on how to use the api with C#, I can't seem
to get the thing working.
The documentation isn't very helpfull either! Almost none...

Thanx,
Bjorn

Adam Boduch

unread,
Sep 1, 2011, 6:16:55 AM9/1/11
to spotclo...@googlegroups.com
Hi,

Are you having trouble authenticating against the API? Or is there a
specific call you're having trouble with?

Adam

Bjorn

unread,
Sep 1, 2011, 9:48:47 AM9/1/11
to spotclo...@googlegroups.com
I tried using the OAuth class from google code to do the authentication but I get:

Error: Bad Request

Your client has issued a malformed or illegal request.


This is the code I'm using:

            string consumerKey = "anonymous";   //Do I use my google account here?
            string consumerSecret = "anonymous";
            Uri uri = new Uri("https://spotcloud.appspot.com/_ah/OAuthGetRequestToken");

            string normalizedUrl = string.Empty;
            string normalizedRequestParameters = string.Empty;

            OAuthBase oAuth = new OAuthBase();
            string nonce = oAuth.GenerateNonce();
            string timeStamp = oAuth.GenerateTimeStamp();
            string sig = oAuth.GenerateSignature(uri,
                consumerKey, consumerSecret,
                string.Empty, string.Empty,
                "GET", timeStamp, nonce,
                OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out normalizedRequestParameters);

            WebClient client = new WebClient();
            var response = client.DownloadString(normalizedUrl+ "?" + normalizedRequestParameters);

Adam Boduch

unread,
Sep 1, 2011, 10:23:32 AM9/1/11
to spotclo...@googlegroups.com
Hi,

I see nothing obviously wrong (I don't know C#) with your code. You
don't need to supply your Google account here - the request token is
used to generate a URI where you can visit with your Google account to
validate.

Have a look here for an example of tested Oauth code:

https://github.com/adamboduch/spotsh/blob/master/src/spotsh/api.py

Adam

Bjorn

unread,
Sep 1, 2011, 11:25:34 AM9/1/11
to spotclo...@googlegroups.com
I don't know python and all the rest of our code is C# so I don't want to get started with python.

I find it weird that a company that want's to make money doesn't supply a sample for one of the most used languages.
Even the documentation isn't what you can a bible, no code comments and only one or two lines description on every api function.

Adam Boduch

unread,
Sep 1, 2011, 11:43:47 AM9/1/11
to spotclo...@googlegroups.com
Hi,

Sorry for the confusion - I'm not suggesting you learn Python. I
thought that example might help you diagnose the problem you're having.

No, we don't have a C# example as we've had no requests for one. Also,
we don't have any in-house C# experts. I'll officially deem this a
request to include a C# example in the documentation.

As for the SpotCloud API documentation reference, this is an ongoing
effort. We're always eager to here how we can improve on it - so if you
could give me some less obscure suggestions, I'd be more than happy to
take care of it.

I'm here to help assist you with your connection troubles, so feel free
to keep me posted on how its going.

Adam

Bjorn

unread,
Sep 1, 2011, 1:46:12 PM9/1/11
to spotclo...@googlegroups.com
I tried another OAuth framework but I'm still getting the Bad Request exception

The call for the request token succeeds but the one for the accesstoken not

I used this request:

https://spotcloud.appspot.com/_ah/OAuthGetAccessToken?oauth_token=4/g68YkQEVcwQX7EZYUYeKiJj7vUgB&oauth_nonce=eea28297-703a-4e3a-a632-aacfaf84cd94&oauth_consumer_key=anonymous&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1314898755&oauth_version=1.0&oauth_signature=a1mSbAKetM0uR8+rPVV2ePIetak=

can you tell me whats wrong with it? I'm loosing hope here

Thanx,
Bjorn

Adam Boduch

unread,
Sep 1, 2011, 1:56:46 PM9/1/11
to spotclo...@googlegroups.com
Hi,

Let me try and replicate your issue. I'll post some feedback here.

Adam

Bjorn

unread,
Sep 1, 2011, 2:24:00 PM9/1/11
to spotclo...@googlegroups.com
Hi,

I got it working now, I had to manually go to the authorization url, login and click the button.

Is there a way to skip this intervention? Not very handy in an api if you have to do manual stuff.

I will provide you with my code when its finished so you can share it or include it in the documentation.

Grtz,
Bjorn

Adam Boduch

unread,
Sep 1, 2011, 2:30:37 PM9/1/11
to spotclo...@googlegroups.com
Hi,

As far as I know, there is no way to circumvent the manual token
authorization. However, once you've authorized the token - you can
reuse it. This is what spotsh does. Once you have an authorized token,
you can store it for use later on.

Adam

Bjorn

unread,
Sep 4, 2011, 8:46:54 AM9/4/11
to spotclo...@googlegroups.com
Got everything up and running and I'm finializing the C# API.

The problem I know have is the https://spotcloud.appspot.com/api/v1/buyer/providers/list.xml is returning an empty list. Is this normal? 

I don't use arguments, don't get an exception only:

<?xml version="1.0" encoding="utf-8"?>
<list>
</list>

Thanx,
Bjorn

Adam Boduch

unread,
Sep 6, 2011, 9:19:06 AM9/6/11
to spotclo...@googlegroups.com
Try this instead:

https://spotcloud.appspot.com/api/v1/buyer/hardware/list.xml

The providers list is deprecated. It is preferred to get the offer (the
hardware) and create instances based on this.

The reason being, before, you had to query the provider list based on
location. Then, you would have to find the hardware you wanted to use -
offered by this provider.

The create instance API used to require both the provider ID and the
hardware ID as parameters. Now it only requires the offer (hardware)
ID. You can query offers the same way you would in the user interface.
So this approach is much more streamlined.

Let me know if you need additional assistance.

Adam

Reply all
Reply to author
Forward
0 new messages