我想在不同的网络中向yammer发帖子。为此我写了下面的代码, 它给服务器找不到例外。
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);
}
答案 0 :(得分:1)
您应该使用SDK for Windows Mobile而不是滚动自己的代码。它可以从Yammer Developer站点获得。您的代码还会在URL参数上传递令牌。不再支持此功能,您需要在身份验证标头上传递它。
ServerNotFoundException突出显示连接问题。也许您没有连接到网络,无法路由连接,或无法通过DNS解析www.yammer.com。