I have a problem with following a user on Instagram with InstaSharp
Here is my code:
private async void Follow()
{
var followMe = await api.FollowUserAsync(userID);
if (followMe.Succeeded)
{
MessageBox.Show("Followed");
}
if (!followMe.Succeeded)
{
MessageBox.Show(followMe.Info.Message);
}
}
And when I call this method in the messageBox it says feedback_required.
How can I fix this?
Also : other functions like Unfollow Login LogOut are working fine I just have problem with Follow function.
Some specific countries ip's will banned in situation like this as you said.
You can use proxies inside your program for this problem if your customers are from those countries.
C# Connecting Through Proxy
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("[ultimate destination of your request]");
WebProxy myproxy = new WebProxy("[your proxy address]", [your proxy port number]);
myproxy.BypassProxyOnLocal = false;
request.Proxy = myproxy;
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
I hope this helps you.
I fixed the issue by changing the proxy server. It seems Instagram was banning my IP for no reason!
Related
I have the following C# code that is attempting to make an https request to a specific url. If I change the URL to point to the QAS server, which is not https then all works fine. I have tried numerous combinations of settings, but nothing that I do seems to get this to work correctly. You can see several of the different combinations of things that I have done in the comments.
var request = (HttpWebRequest)WebRequest.Create(nextUrl);
request.AllowAutoRedirect = false;
request.UseDefaultCredentials = true;
request.KeepAlive = false;
//request.PreAuthenticate = true;
//request.Credentials = CredentialCache.DefaultNetworkCredentials;
//request.Credentials = new NetworkCredential("name", "pass", "domain");
ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
HttpWebResponse response;
using (response = (HttpWebResponse)request.GetResponse())
{
//Do Something
}
Your code for the certificate callback looks incorrect, it should look:
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback(AcceptAllCertifications);
I'm assuming you have the proper method signature for the AcceptAllCertifications. Also the class you're utilizing if nextUrl is http it will default to unsecure, if it is https it will default to secure.
I am facing some problems when using the HttpClient class to access to a Delicious API. I have the following code:
try
{
const string uriSources = "https://api.del.icio.us/v1/tags/bundles/all?private={myKey}";
using (var handler = new HttpClientHandler { Credentials = new
NetworkCredential("MyUSER", "MyPASS") })
{
using (var client = new HttpClient(handler))
{
var result = await client.GetStringAsync(uriSources);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "ERROR...", MessageBoxButton.OK);
}
When running the code above I am getting the following: Response status code does not indicate success: 401 (Unauthorized).
So, how could I get this work? Is it possible?
Thanks in advance
Regards!
I had the exact same problem myself. It seems the HttpClient just disregards the credentials set in the HttpClientHandler.
The following shall work however:
using System.Net.Http.Headers; // For AuthenticationHeaderValue
const string uri = "https://example.com/path?params=1";
using (var client = new HttpClient()) {
var byteArray = Encoding.ASCII.GetBytes("MyUSER:MyPASS");
var header = new AuthenticationHeaderValue(
"Basic", Convert.ToBase64String(byteArray));
client.DefaultRequestHeaders.Authorization = header;
var result = await client.GetStringAsync(uri);
}
No need for the handler.
Source: http://www.snip2code.com/Snippet/13895/Simple-C---NET-4-5-HTTPClient-Request-Us
This is an old post but thought to add my reply for someone facing similar issue and browsing answers...
I faced similar issue. In my case, setting Domain property for NetworkCredentials worked. You can try setting Domain.
The code you are showing works for me against an authenticated resource. I suspect Delicious is doing something weird.
Considering you are on Windows Phone, it is a pain to debug with Fiddler, so what I suggest is getting a Runscope account. Install this message handler which will redirect your request via the RunScope debugger. Once you do this, I suggest you look at the www-authenticate header and examine what that is returning.
If all else fails you can always set the Authentication header directly with basic auth credentials. You don't need to use the Credentials class.
Does anyone have a snippet of code for connecting to the Asana API using c#?
There is a Hello World application on their site but unfortunately it is written in ruby.
https://asana.com/developers/documentation/examples-tutorials/hello-world
I'm doing this as a quick side project and can only dedicate a small amount of time to it. Any help would be greatly appreciated.
Thanks in advance!
Follow up:
I've tried multiple ways of accessing/authentication and I keep getting a 401 Not Authorized error.
My latest code looks like this:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://app.asana.com/api/1.0/users/me");
request.Method = "GET";
request.Headers.Add("Authorization: Basic " + "*MyUniqueAPIKey*");
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "application/json";
WebResponse ws = request.GetResponse();
Try this code. I was able to get a list of users with it:
const string apiKey = "whateverYourApiKeyIs";
public string GetUsers()
{
var req = WebRequest.Create("https://app.asana.com/api/1.0/users");
SetBasicAuthentication(req);
return new StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd();
}
void SetBasicAuthentication(WebRequest req)
{
var authInfo = apiKey + ":";
var encodedAuthInfo = Convert.ToBase64String(
Encoding.Default.GetBytes(authInfo));
req.Headers.Add("Authorization", "Basic " + encodedAuthInfo);
}
This just returns the data as a string. Parsing the JSON is left as an exercise for the reader. ;)
I borrowed the SetBasicAuthentication method from here:
Forcing basic http authentication for HttpWebRequest (in .NET/C#)
You could try using my library, AsanaNet :)
https://github.com/acron0/AsanaNet
You need to do HTTP requests, there are so many tutorials like this one
http://msdn.microsoft.com/en-us/library/debx8sh9(v=vs.80).aspx
Users are authenticating to a REST WCF Service (my own). The credentials are sent through AJAX with Javascript and JSON format. The service reply with a OK and little info (redirect url) to the client, when authenticated.
Now, There are a new method provided for external authentication, and I have to create a compact code snippet that are easy to paste & run inside a asp.net code file method.
A typical wcf request could end up like this,
http://testuri.org/WebService/AuthenticationService.svc/ExtLogin?cId=197&aId=someName&password=!!pwd
My code snippet so far,
protected void bn_Click(object sender, EventArgs e)
{
WebHttpBinding webHttpBinding = new WebHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress(url);
ContractDescription cd =
ContractDescription.GetContract(typeof(IAuthenticationService));
ServiceEndpoint sep = new ServiceEndpoint(cd);
sep.Behaviors.Add(new WebHttpBehavior());
sep.Address = endpointAddress;
sep.Binding = webHttpBinding;
var resp = new ChannelFactory<IAuthenticationService>(sepREST).CreateChannel();
LoginResult result = resp.ExtLogin(cId, aId, hashPwd);
Response.Redirect(result.RedirectUri);
// I.e. http://testuri.org/Profile.aspx (Require authenticated to visit)
}
I recieve correct authenticated reply in the resp/result objects. So, the communication are fine. When redirecting to the actual website, I'm not authenticated. I can't locate the problem? If I take the URI above (with valid credentials) and paste into my Webbrowser URL, and then manually type the uri, i'm authenticated.
I've spent a day searched the net for this, without success.
There are a LOT of info but none seem to apply.
What am I missing?
I also tried another approach but the same problem persist.
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uriWithParameters);
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.ContentType = "application/json";
request.Accept = "application/json";
request.Method = "GET";
string result;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
result = reader.ReadToEnd();
JavaScriptSerializer jsonDeserializer = new JavaScriptSerializer();
LoginResult contact = jsonDeserializer.Deserialize<LoginResult>(result);
Response.Redirect(result.RedirectUri);
I'm not sure about this answer, but will offer it anyway as nobody else has posted:
I think it's because the request that has been authenticated is the request sent via code.
When you redirect it's a totally different request - so is still not authenticated.
All authentication techniques require some way of maintaining the authenticated state across 'stateless' requests = session cookies or some kind of authentication token.
Whatever token you get back from the call to the authentication service needs to be available to your website requests as well - dumping the token from the request into a cookie might be an option.
Can you see (in something like Fiddler) an auth token being sent as part of the request to 'RedirectUrl'?
How can I check whether a page exists at a given URL?
I have this code:
private void check(string path)
{
try
{
Uri uri = new Uri(path);
WebRequest request = WebRequest.Create(uri);
request.Timeout = 3000;
WebResponse response;
response = request.GetResponse();
}
catch(Exception loi) { MessageBox.Show(loi.Message); }
}
But that gives an error message about the proxy. :(
First, you need to understand that your question is at least twofold,
you must first check if the server is responsive, using ping for example - that's the first check, while doing this, consider timeout, for which timeout you will consider a page as not existing?
second, try retrieving the page using many methods which are available on google, again, you need to consider the timeout, if the server taking long to replay, the page might still "be there" but the server is just under tons of pressure.
If the proxy needs to authenticate you with your Windows credentials (e.g. you are in a corporate network) use:
WebRequest request=WebRequest.Create(url);
request.UseDefaultCredentials=true;
request.Proxy.Credentials=request.Credentials;
try
{
Uri uri = new Uri(path);
HttpWebRequest request = HttpWebRequest.Create(uri);
request.Timeout = 3000;
HttpWebResponse response;
response = request.GetResponse();
if (response.StatusCode.Equals(200))
{
// great - something is there
}
}
catch (Exception loi)
{
MessageBox.Show(loi.Message);
}
You can check the content-type and length, see MSDN HTTPWebResponse.
At a guess, without knowing the specific error message or path, you could try casting the WebRequest to a HttpWebRequest and then setting the WebProxy.
See MSDN: HttpWebRequest - Proxy Property