0

I am currently experimenting with the HTTP request. I have successfully managed to do get requests and I have read on doing post request with HTTP request. Now I am trying to work with the yahoo API and in order to use the Yahoo api it states that at

The Message Management API can be used to send a message to another Yahoo! Messenger contact. The API is very simple to use, as shown here. Note that the contact that the message is sent to is part of the URI, using the following format:<server>/v1/message/<network>/<contactID>

POST /v1/message/yahoo/targetYahooId?sid=msgrsessionid  
Host: rcore1.messenger.yahooapis.com  
Authorization: < Standard OAuth credentials >  
Content-Type: application/json;charset=utf-8  
Content-Length: 25  
{  
    "message" : "Hey there"  
}  

Now I have an OAuth string which I obtained from get using the HttpWebRequest object. The string is something like this

oauth_token=A%3Dvh....aRg--&oauth_token_secret=bd46a....c9239&oauth_expires_in=3600&oauth_session_handle=ALtT.....3J1N4Zg--&oauth_authorization_expires_in=784964948&xoauth_yahoo_guid=TUSKED5...NCIA

UPDATE

Now my question are as follows :

1- If I am using WebRequest object in C# what would my URI look like

2- I understand that it requires a JSON type object. How do i even know what OAuth parameters are ?

Rajeshwar
  • 11,179
  • 26
  • 86
  • 158

4 Answers4

1

One thing you'll need to change is the content type:

request.ContentType = "application/json;charset=utf-8";

And of course, the url.

jrummell
  • 42,637
  • 17
  • 112
  • 171
0

you need to change the url on the line with the url in it

you need to change the content-type line

you need to make the payload into a json string then convert it to a byte array (byteArray in the sample)

either assemble the json by hand "{ foo:'bar'}" etc or use json.net

and set the content-length

pm100
  • 48,078
  • 23
  • 82
  • 145
  • and you have to use OAuth to authenticate your user, this link should help http://www.deanhume.com/Home/BlogPost/a-simple-guide-to-using-oauth-with-c-/49 – makim Mar 05 '13 at 21:05
  • I have already doen the authentication and have an access token – Rajeshwar Mar 05 '13 at 21:07
0

Looks like it's expecting a JSON object for the request body. Depending on the version of .NET you're using, you can either use a Javascript serializer as shown here (https://stackoverflow.com/a/7003815/939080) or JSON.NET (http://james.newtonking.com/projects/json-net.aspx) to convert your form collection into JSON output.

Community
  • 1
  • 1
Chris Disley
  • 1,286
  • 17
  • 30
0

You are asking an open-ended question that would require people to write a bunch of code for you if you want a specific and complete answer. As others have pointed out, there are several issues that you'd need to deal with:

  • The JSON payload, which would be a straightforward matter of putting the JSON string in the request body via the byteArray used in the code sample.
  • The content type, which you would need to change as described by jrummell.
  • The OAuth credentials, which is a kettle of fish you'll need to read about, understand, and acquire a library for. Here's a good place to start looking for a library.
Jollymorphic
  • 3,510
  • 16
  • 16