I am using TweetSharp Api and I have some problems concerning the service.GetRequestToken().
For example in my Asp.net C# function I do a simple sendTweet().
On my Tweeter account my App is not registered.
So I get an Unauthorized Response and I call my Authorize method.
TwitterService service = new TwitterService("ConsumerKey", "ConsumerSecret");
OAuthRequestToken requestToken = service.GetRequestToken("callbacklink");
Uri uri = service.GetAuthorizationUri(requestToken);
return new RedirectResult(uri.ToString(), false);
The problem is that when I'm redirected to the Twitter authorization window the first time I have the good window but if i try again wihtout having authorized my app, the url is like :
https://api.twitter.com/oauth/authorize?oauth_token=?
And I get an error.
If I continue I get the good url and after the empty one and so on...
Do you have any explaination ?
Thanks a lot !
You problably forget configure the "Callback URL" field on Setting tab of twitter app.
You probably forget configure the "Callback URL" field on Setting tab of twitter app.
Note: localhost will not work, you can use localhost using trick see the details:
Can you run in localhost an app that use Twitter OAuth?
There is nor probleme anymore, I just store the user token in a db and get it at every access.
Related
I want to integrate twitter in my ASP.Net web site with C# . I want to implement a profile page in which user should be able to sign in from twitter. After clicking on "Sign Up via Twitter" Button. I have made a twitter application and i am doing this thing with OAuth. After getting user details i want to add them to my SQL Server Database(So that in future user can sign in using these details).
IT gives an exception at runtime.The exception is
The remote server returned an error:(403) Forbidden.so please answer if you have done this kind of stuff.
I have already search all around on the internet,am i doing something wrong here?
Add the following line:
request.UseDefaultCredentials = true;
This will let the application use the credentials of the logged in user to access the site. If it's returning 403, clearly it's expecting authentication.
It's also possible that you (now?) have an authenticating proxy in between you and the remote site. In which case, try:
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
Hope this helps.
I want that my Windows Phone 8 app uses LinkedIn in order to search companies and get contacts. To do so I need an Access Token and, to get that, I need an Authorization Code.
As far as I have read, the LinkedIn API uses OAUTH2 and the url to get the Authorization Code is the following:
https://www.linkedin.com/uas/oauth2/authorization?response_type=code
&client_id=YOUR_API_KEY
&scope=SCOPE
&state=STATE
&redirect_uri=YOUR_REDIRECT_URI
The problem is the REDIRECT URI parameter. I don't want that, because I just want to get the Authorization Code, and then get the Token with the code.
Do you know if is there any way to avoid redirecting? Or using some kind of redirect which doesn't bring you to other webpage?
I decided to use a custom host, so now the problem is solved.
In case anyone has a similar issue, I struggled with this and found an easier way (maybe not the correct way).
I redirected to a made up address (http://madeupaddress.com) and on the Navigating event checked if the url started with my made up address, if so, i closed the browser and take the token from the e.URI.Query parameters, then apply for the access token using the code.
Thanks go to Vittorio Bertocci
Question:
I'm using a DropBox csharp API from here:
https://github.com/dkarzon/DropNet
From the Unit tests, and the only working sample from here
https://github.com/dkarzon/DropNet/blob/master/DropNet.Samples/DropNet.Samples.Web/Default.aspx.cs
I figured that it works like this:
DropNet.DropNetClient client = new DropNet.DropNetClient(strApiKey, strAppSecret);
DropNet.Models.UserLogin login = client.GetToken();
client.UserLogin = login;
var accountInfo = client.AccountInfo();
str = accountInfo.quota_info.quota.ToString();
The probem is, it throws an exception on accountinfo. (System.Net.HttpStatusCode.Unauthorized)
Everything before works fine, I get the login (usertoken & usersecret) .
I think my problem is this part of the sample application:
var url = _client.BuildAuthorizeUrl(Request.Url.ToString() + "?dropboxcallback=1");
Response.Redirect(url);
Where it redirects to dropbox for a login...
I don't have a web application, so I have no URL...
What I have is a console application, that should make a backup of my database every evening automatically as a service, for which it certainly is very bad requiring a webbrowser and a user which has to type in email/username + password.
How can I do a login by directly supplying the hardcoded username and password ?
If I use the sample application, then it works, but that requires typing in the username and password on the web, and that sucks big time for a console application...
As far as I know from other API's (facebook, google, stack exchange etc.) you'll have to redirect your user to a webpage of Dropbox, where it will grant permissions to you to use it's account to perform things.
So in general it is not possible to achive this without a webbrower. Otherwise you'll have to perform really dirty hacks to hack arround the permission system of dropbox.
Please have a look at "OAuth 2.0 authorization flow" on google.
Here's a diagram I found at Yahoo which show's how it works:
For uisng the DropnetClient's 4 argument constructor also we need to build web based url and allow the user to authenticate his account this is compusory thing, accesstoken will generate after the user hit allow button in authentication process
As GameScripting explained the Dropbox API uses oauth which requires user login through the dropbox website to authenticate the access tokens.
Checkout the documentation here: http://dkdevelopment.net/what-im-doing/dropnet/ for the 3 step process.
What sort of application are you building? Normal process is to load a browser control inside the application and navigate to the login URL with it.
Also have a look at the sample Windows Phone app to give you an idea of how this process works: https://github.com/dkarzon/DropNet/blob/master/DropNet.Samples/DropNet.Samples.WP7/MainPage.xaml.cs
Instead of hardcoding the username and password, you can hardcode the OAuth access token.
First, create a simple program (using the same app key) that follows the standard browser-based authorization flow. Then use it to authorize the app with the desired user. This will give you an OAuth access token (a "token" and "token secret") associated with that user and your app key.
Then, in your service-style application, just hardcode the OAuth access token (using DropNetClient's 4-argument constructor).
It is possible, using SharpBox - tested, works.
One needs to acquire the AccessToken as a one-time-action manually, then after that, one can omit the login page and use the saved AccessToken.
http://www.jayway.com/2012/02/06/unboxing-dropbox-and-sharpbox-2/
The magic line is:
Globals.DropBox.Token = AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxStorageProviderTools
.ExchangeDropBoxRequestTokenIntoAccessToken(
Globals.DropBox.config
, Globals.DropBox.AppKey, Globals.DropBox.AppSec
, Globals.DropBox.requestToken
);
I'm trying to use the Facebook SDK 5.2.1 to ultimately create a test user, however even what I believe is the simple example of getting the list of test accounts isn't working for me. I get the OAuthException "An access token is required to request this resource."
Here's my code (replace APP ID and APP SECRET with my own):
FacebookOAuthClient oauth = new FacebookOAuthClient { AppId = "APP ID", AppSecret = "APP SECRET" };
dynamic tokenRes = oauth.GetApplicationAccessToken();
fbClient = new FacebookClient(tokenRes.access_token);
dynamic response = fbClient.Get("APPID/accounts/test-users");
However, I get the exception on the fbClient.Get line.
Any idea as to what's wrong?
Thanks,
Chad
After hours of trying various things and reading various web pages/blogs, I found the reason it wasn't working. In my app settings, I had my app type set to a Native/Desktop App. Changing this to Web, allows the above scenario to work. I'm not yet quite sure of what other differences exist between web vs native facebook apps. My app is certainly only being used via a desktop application and I can't understand why I need to set this to Web just to allow me to create test users.
This code works in my app:
var app = new FacebookClient(FacebookApplication.Current.AppId,
FacebookApplication.Current.AppSecret);
dynamic result = app.Post(string.Format("{0}/accounts/test-users",
FacebookApplication.Current.AppId),
new { installed = true, permissions = "user_about_me" });
The reason why you are receiving the exception OAuthException is because you have not yet got the permission of the user.
To do a Graph API call on the current user, you need to get the user to accept the permissions that you require FIRST and then do the Graph API call.
You need to get the user to a browser some how in your application, as there is not an authentication flow which doesn't require a browser window.
Check out this URL to view the authentication flows:
http://developers.facebook.com/docs/authentication/
I have a .net website and I want to post messages by the facebook api to every user's wall.I want via an application to post messages, but the error message when i execute Stream.Publish is "The user hasn't authorized the application to perform this action".
I am using the Facebook Developer Toolkit. I believe that i make something wrong in the configuration of the settings of my facebook application but I am not sure.
Have you tried the samples It may help you understand if you do something wrong with your code.
Add the following this in the Page_PreInit() event
base.RequiredPermissions = new List();
base.RequiredPermissions.Add(Facebook.Schema.Enums.ExtendedPermissions.publish_stream);
base.RequireLogin = true;
or use
Response.Redirect("http://www.facebook.com/login.php?api_key=" + ApiKey + "&next=http://apps.facebook.com/yourapplication/&display=page&locale=en_US&return_session=0&fbconnect=0&canvas=1&legacy_return=1&req_perms=publish_stream");