I am using dropnet api to access dropbox using c#.i send my apikey and secret key,i get token in response.but when i try to get account info or delete a file it throws unauthorized use exceptions.can any one help me.my code is as follow.
DropNet.DropNetClient client = new DropNet.DropNetClient("xxxxxxxxx", "xxxxxxxxx");
DropNet.Models.UserLogin login = client.GetToken();
client.UserLogin = login;
string st=client.BuildAuthorizeUrl(client.UserLogin,null);
client.Delete("/Public/testsk");
var accountInfo = client.AccountInfo();
Regards,
Shah Khalid.
Dropbox API uses standard http error codes,
in your case, 401 usually means that user access token expired or revoked and it should recreated,
All you need to do is re-authenticate end user dropbox account by doing next steps in this order:
your application basic authentication:
client = new DropNetClient(Settings.Default.DropboxApiKey, Settings.Default.DropboxApiSecret);
client.GetToken();
Let user login Dropbox with their account and approve your Dropbox app:
string url = Client.BuildAuthorizeUrl();
Retrieve and save authenticated user token:
UserLogin accessToken = Client.GetAccessToken();
Account.Token = accessToken.Token;
Account.Secret = accessToken.Secret;
Account.Status = AccountStatus.Active;
last - save account data in your app - Account.Save()
Related
I have Implemented a code of Embedded Signing Sender View in C# .Net core
public string EmbeddedSigning(string accountId, string envelopeId)
{
try
{
EnvelopesApi envelopesApi = new EnvelopesApi();
// Start the embedded sending session
ReturnUrlRequest urlRequest = new ReturnUrlRequest();
urlRequest.ReturnUrl = "https://account-d.docusign.com/logout";
// generate the embedded sending URL
ViewUrl viewUrl = envelopesApi.CreateSenderView(accountId, envelopeId, urlRequest);
return viewUrl.Url;
}
catch (DocuSign.eSign.Client.ApiException ex)
{
return "";
}
}
After successfully sending the envelope DocuSign page stayed as logged in.
I have tried to logout using ReturnUrl but its not working. Kindly suggest is there any other way to achieve this?
An embedded signer is not "logged in" to DocuSign since an embedded signer does not login.
If you used Authorization Code grant or Implicit grant with your application to obtain an access token, then the person who authenticated is still logged into your application.
To log them out, clear your app's record of the user's access token and (for authorization code grant) the refresh token.
Basically what I'm trying to do is to get recent tweets from a user and do stuff with them. I'm using Tweetinvi with PIN-based authentication, as described on the website, like this:
// Create a new set of credentials for the application
var appCredentials = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET");
// Go to the URL so that Twitter authenticates the user and gives him a PIN code
var url = CredentialsCreator.GetAuthorizationURL(appCredentials);
// This line is an example, on how to make the user go on the URL
Process.Start(url);
// Ask the user to enter the pin code given by Twitter
var pinCode = Console.ReadLine();
// With this pin code it is now possible to get the credentials back from Twitter
var userCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(pinCode, appCredentials);
// Use the user credentials in your application
Auth.SetCredentials(userCredentials);
Now the problem is that I have to sign in and connect to Twitter every time I launch my application via browser, which is mildly annoying. I've tried to save my authentication details in a text file (Consumer Key, Consumer Secret, Access Token, Access Token Secret), and then just insert the info into appCredentials and userCredentials, but with no results, as I keep getting TwitterNullCredentialsException. So how do I save my credentials so that I don't have to reconnect on every launch?
I am the main developer of Tweetinvi.
If you store the 4 credentials information you can then reuse them with 2 different solutions :
Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
// OR
var creds = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
Auth.SetCredentials(creds);
The documentation might help you set up your application : https://github.com/linvi/tweetinvi/wiki/Introduction
Scenario:
User has completed the OAuth process and has given our app publish_actions, publish_stream, user_friends, and user_photos permissions.
While we have the user token from the user logging in, we have retrieved and persisted the user's Facebook id
Also while we have the user token, we have created a photo album to later post photos to and persisted the Facebook album id
NOTE: We have not persisted the user token for legacy reasons
At a later time, we attempt to post a photo to the album previously created using the following code:
FacebookClient client = null;
Dictionary<string, object> parameters = null;
string path;
FacebookMediaObject media = null;
client = new FacebookClient();
client.AppId = "{our app id}";
client.AppSecret = "{our app secret}";
media = new FacebookMediaObject();
media.ContentType = "image/jpg";
media.FileName = "AnyAllContactTypesProblem.jpg";
media.SetValue(File.ReadAllBytes(Server.MapPath(".") + "\\" + media.FileName));
parameters = new Dictionary<string,object>();
parameters.Add("name",
"Test Image 1");
parameters.Add("source",
media);
path = "/" + "{album id}" + "/photos";
dynamic result = client.Post(path,
parameters);
The POST operation results in the following exception:
(OAuthException - #102) A user access token is required to request this resource.
The Facebook documentation indicates that an "app token" which is derived from the app id and app secret can be used as the access token for posting a photo on someone's behalf as long as publish_stream permission has been provided to the app which it has in our case.
Are we missing something needed in the code above or has Facebook changed the required permissions for posting photos?
Thanks in advance.
I don't know from where did you read this-
an "app token" which is derived from the app id and app secret can be used as the access token for posting a photo on someone's behalf as long as publish_stream permission has been provided to the app which it has in our case.
But this is not true. Once you got the publish permission, you can post the stories/feeds on the wall and get the basic info using the app access token. Posting the photos is not allowed! Here's what the documentation says-
App access tokens can also be used to publish content to Facebook on behalf of a person who has granted an open graph publishing permission to your application. Reference
One thing that you can do-
Save the extended token to your server (that expires in 60-days, after that user must go through the login again to get the new token), to get the extended token-
GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={short-lived-token}
I want to get user access token(Graph API Explorer) from facebook without login
I tried with app access token but I am unable to get comments for the posts
Code is for app access token:
string appId = "APP_Id";
string appSecret = "APP_Secret";
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = appId,
client_secret = appSecret,
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
var accessToken = fb.AccessToken;
Any ideas? Thanks in advance.
You have to create a new instance of the FacebookClient with the Users AccessToken to get info about the User!
I think here is no way you get the Token without calling the FB.Login
From the API Documentation:
User Access Token – The user token is the most commonly used type of token. This kind of access token is needed any time the app calls
an API to read, modify or write a specific person's Facebook data on
their behalf. User access tokens are generally obtained via a login
dialog and require a person to permit your app to obtain one.
I need help on oAuth authentication to facebook. I am able to do the steps that facebook API mentioned and successfully authenticated, get my profile information as well as post to my news feed.
I want my application to login automatically rather than routing to Facebook login page on behalf of a user(i.e. get credentials from db and do auto oauth) . So that the user can type a message on application and click on button should submit a post to facebook page.
Thanks
What you need to get is an access token. This is a key which allows you continued access to the account until your the token expires or the user cancels it.
When you first authenticate if you have set the required permissions you get an authtoken which you can store and use to initiale further calls.
var client = new FacebookClient("my_access_token");
dynamic result = client.Get("19292868552_118464504835613");
string id = result.id;
string fromName = result.from.name;
string fromCategory = result.from.category;
string message = result.message;
int likes = result.likes;
foreach (dynamic comment in result.comments.data) {
string commentId = comment.id;
string commentMessage = comment.message;
}
see this article for details about the process:
http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/