protected void Page_Load(object sender, EventArgs e)
{
string uriString = "https://api.twitter.com/1.1/statuses/retweet.json";
NameValueCollection nvc1 = new NameValueCollection();
nvc1.Add("x-csrf-token", "70969d00e314c54642678c18752de66c");
nvc1.Add("X-Twitter-Active-User", "yes");
nvc1.Add("x-twitter-auth-type", "OAuth2Session");
nvc1.Add("authorization", "Bearer AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw");
string str3 = postFormData(new Uri(uriString), "id=1164875811846930432&tweet_stat_count=0", "https://twitter.com/Ghareeb_ELMahg/status/1164875811846930432", string.Empty, string.Empty, string.Empty, "https://twitter.com", nvc1);
}
public string postFormData(Uri formActionUrl, string postData, string Referes, string Token, string XRequestedWith, string XPhx, string Origin, NameValueCollection nvc)
{
this.gRequest = (HttpWebRequest)WebRequest.Create(formActionUrl);
this.gRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0";
this.gRequest.Accept = "application/json, text/javascript, */*; q=0.01";
this.gRequest.Headers["Accept-Language"] = "en-US,en;q=0.5";
this.gRequest.KeepAlive = true;
this.gRequest.Method = "POST";
this.gRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
this.gRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
this.gRequest.Host = "api.twitter.com";
this.gRequest.CookieContainer = new CookieContainer();
foreach (string name in nvc)
this.gRequest.Headers.Add(name, nvc[name]);
if (!string.IsNullOrEmpty(Referes))
this.gRequest.Referer = Referes;
if (!string.IsNullOrEmpty(Origin))
this.gRequest.Headers.Add("Origin", Origin);
//this.ChangeProxy(this.proxyAddress, this.port, this.proxyUsername, this.proxyPassword);
if (this.gCookies != null && this.gCookies.Count > 0)
{
this.setExpect100Continue();
this.gRequest.CookieContainer.Add(this.gCookies);
this.gRequest.CookieContainer.Add(formActionUrl, new Cookie("ct0", this.csrf_token));
}
try
{
this.setExpect100Continue();
string.Format(postData);
byte[] bytes = Encoding.GetEncoding(1252).GetBytes(postData);
this.gRequest.ContentLength = bytes.Length;
Stream requestStream = this.gRequest.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
this.gResponse = (HttpWebResponse)this.gRequest.GetResponse();
}
catch (WebException ex)
{
StreamReader streamReader = new StreamReader(ex.Response.GetResponseStream());
string end = streamReader.ReadToEnd();
streamReader.Close();
return end;
}
if (this.gResponse.StatusCode != HttpStatusCode.OK)
return "Error in posting data";
this.setExpect100Continue();
this.gResponse.Cookies = this.gRequest.CookieContainer.GetCookies(this.gRequest.RequestUri);
if (this.gResponse.Cookies.Count > 0)
{
if (this.gCookies == null)
{
this.gCookies = this.gResponse.Cookies;
}
else
{
foreach (Cookie cookie in this.gResponse.Cookies)
{
bool flag = false;
foreach (Cookie gCookie in this.gCookies)
{
if (gCookie.Name == cookie.Name)
{
gCookie.Value = cookie.Value;
flag = true;
break;
}
}
if (!flag)
this.gCookies.Add(cookie);
}
}
}
StreamReader streamReader1 = new StreamReader(this.gResponse.GetResponseStream());
string end1 = streamReader1.ReadToEnd();
streamReader1.Close();
return end1;
}
``
thrwoing an error "Could not authenticate you." with code 32
This does not look like the correct way to build a request to the API, this looks like a browser request, you might want to use a library like GitHub - linvi/tweetinvi: Tweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)... to get your code to interact with Twitter APIs
1 Like
Your post is lacking in a lot of detail. You’ve just posted code.
What are you trying to achieve, and what errors are you seeing?
We would really appreciate more detail here.
with above code when i am trying to retweet the tweet it is giving me the error of could not authenticate you with code 32
can you help me with this stuff because i have only this stuff and i am instructed to move with this stuff only
system
Closed
#6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.