srujana
srujana

Reputation: 67

How to post messages to yammer private network

I want to post messages to yammer in different network. For this I have wrote the below code , it's giving the server not found exception.

               rawtoken = Security.GetRawToken();

                //TODO
                //get list of Yammer tokens for this user
                WebClient wc = new System.Net.WebClient();
                wc.DownloadStringCompleted += wc_DownloadStringCompleted;
                wc.DownloadStringAsync(new Uri("https://www.yammer.com/api/v1/oauth/tokens.json?access_token=" + rawtoken));
 void wc_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
    {
        string tokens = e.Result;
        MessageBox.Show(tokens);
        List<Response> myDeserializedObjList = (List<Response>)Newtonsoft.Json.JsonConvert.DeserializeObject(tokens,typeof(List<Response>));
        List<Response> response = myDeserializedObjList.Where(item => item.network_id == "992371").ToList();
        accessToken = response[0].token;

        WebClient wc = new System.Net.WebClient();
       Uri uri = new Uri("https://www.yammer.com/api/v1/messages.json?access_token=" + accessToken);

        student ns = new student();
      //  wc.Headers["Authorization"] = "Bearer " + accessToken;  //use discoEN token here
        String data = "group-id=" + ns.group_id + "&body=" + ns.body;
        wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
        wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
        wc.Encoding = Encoding.UTF8;
        wc.UploadStringTaskAsync(uri, data);

    }

    private void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
    {
        MessageBox.Show(e.Result);
    }

Upvotes: 0

Views: 293

Answers (1)

Brian Lyttle
Brian Lyttle

Reputation: 14579

You should use the SDK for Windows Mobile rather than rolling your own code. It is available from the Yammer Developer site. Your code also passes the token on a URL parameter. This is no longer supported and you need to pass it on the authentication header.

A ServerNotFoundException highlights a connectivity problem. Perhaps you are not connected to the network, cannot route connections, or cannot resolve www.yammer.com via DNS.

Upvotes: 1

Related Questions