我正试图从Twitter Home TimeLine获取状态,但它失败了。
在更新状态时使用POST方法时没有问题,并且有效。 这里,代码示例:
$post_body = [System.Text.Encoding]::ASCII.GetBytes("status=" + $status);
[System.Net.HttpWebRequest] $request = [System.Net.WebRequest]::Create("https://api.twitter.com/1.1/statuses/update.json");
$request.Method = "POST";
$request.Headers.Add("Authorization", $oauth_authorization);
$request.ContentType = "application/x-www-form-urlencoded";
$body = $request.GetRequestStream();
$body.write($post_body, 0, $post_body.length);
$body.flush();
$body.close();
$response = $request.GetResponse();
但是,当使用GET方法读取Home Timeline时,我总是收到错误消息。
Exception calling "GetRequestStream" with "0" argument(s): "Cannot send a content-body with this verb-type."
At line:42 char:1
+ $response = $request.GetRequestStream()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ProtocolViolationException
这里是我使用的代码:
[System.Net.HttpWebRequest] $request = [System.Net.WebRequest]::Create("https://api.twitter.com/1.1/statuses/home_timeline.json");
$request.Method = "GET";
$request.Headers.Add("Authorization", $oauth_authorization);
$request.ContentType = "application/x-www-form-urlencoded";
$response = $request.GetRequestStream();
抱歉我的英语不好。