新浪API获取评论列表时出现问题,求助
public static string GetResult(string url)
{
string username = "账户";
string password = "密码";
string usernamePassword = username + ":" + password;
WebRequest webRequest = WebRequest.Create(url);
HttpWebRequest myReq = webRequest as HttpWebRequest;
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
myReq.Credentials = myCache;
myReq.Headers.Add("Authorization", "Basic " +
Convert.ToBase64String(new System.Text.ASCIIEncoding().GetBytes(usernamePassword)));
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
return reader.ReadToEnd();
}
public static string GetResult(string url)
{
WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
string str = string.Empty;
try
{
str = client.DownloadString(url);
}
catch
{
throw;
}
finally
{
client.Dispose();
}
return str;
}
两个方法都不行,comments/show.json不能获取数据,但users/show.json和user_timeline.json可以获取,用的是ipad版微博的key,为什么同样是需要登录的,获取评论就不行,求助啊
api
[解决办法]
Basic 方式新浪是测试用的。正规应该用 OAuth2 ,为什么不用新浪的SDK呢?
http://open.weibo.com/wiki/SDK