2016-08-19 11 views
0

DropNet API를 사용하여 로컬 파일의 공유 링크를 검색하고 있지만 null이기 때문에 GetAccessToken()을 지나갈 수 없습니다. GetShare() 던져C#을 사용하여 로컬 드롭 박스 파일의 공유 URL을 얻는 방법

var _client = new DropNetClient(APIKEY, APISEC); 
_client.GetToken(); 
var url = _client.BuildAuthorizeUrl(); 
Process.Start(url); 
var accessToken = _client.GetAccessToken();      
var shareResponse = _client.GetShare("/Getting Started.rtf"); 
MessageBox.Show(shareResponse.Url); 

예외 : 여기

지금까지 내 코드입니다

그것은 내가 브라우저를 시작하고 방법에 뭔가하는
System.Reflection.TargetInvocationException 

하지만 난에 있었어요 이 시간 동안, 어떤 도움을 주셔서 감사합니다!

답변

1

시간이 흐르면서 드디어 Spring.Social (NuGet)의 문서를 발견했습니다.

는 여기있다 : 새로운 응용 프로그램에 대한

  1. 가입은 여기에 프로그램에 링크 :

  2. DropBox/Developer/Apps는 NuGet 패키지 Spring.Social.Dropbox를 설치합니다.

  3. 다음 예를 사용하여 연결하십시오.

    using Spring.Social.Dropbox.Api; 
    using Spring.Social.Dropbox.Connect; 
    using Spring.Social.OAuth1; 
    
    private void ShareViaDropbox(string[,] filesNameLink) 
    { 
        try 
        { 
         if (CheckForInternetConnection()) // cant use dropbox without internet. 
         { 
          string consumerKey = "<get this from dropbox>"; 
          string consumerSecret = "<get this from dropbox>"; 
    
          DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(consumerKey, consumerSecret, AccessLevel.Full); 
          IOAuth1Operations oauthOperations = dropboxServiceProvider.OAuthOperations; 
    
          // I used an xml file to store the key (probably not the most secure later I will write an encryption). 
          string[] storedToken = GetTag("<DropBoxToken>", ",").Split(','); 
          OAuthToken oauthAccessToken = new OAuthToken(storedToken[0], storedToken[1]); 
    
          // testing if we got something from the earlier xml tag. 
          if (oauthAccessToken.Value == string.Empty || oauthAccessToken.Value == "") 
          { 
           Console.Write("Getting request token..."); 
           OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; 
           Console.WriteLine("Done"); 
           OAuth1Parameters parameters = new OAuth1Parameters(); 
           string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); 
    
           Console.WriteLine("Redirect user for authorization"); 
    
           // let the user know they have to sign in and chose the correct dropbox. this is also where most documentation leaves off! 
           MessageBox.Show(
            "This is the first time you have connected to DropBox. A browser will open and direct you the the DropBox authentication page. When you prompted, please sign in and then choose the [named] DropBox." + Environment.NewLine + 
            "Once you have succesfully compleaded the authorization confirmation from DropBox, you may close the browser to continue." + Environment.NewLine + 
            Environment.NewLine + 
            "Click 'Ok' to proceed", "DropBox Authentication Required.", MessageBoxButtons.OK, MessageBoxIcon.Information); 
           Process.Start(authenticateUrl); 
    
           // halt the program until the user has authenticated. 
           MessageBox.Show("Click 'OK' when authorization has succeeded.", "DropBox Authentication - WAIT", MessageBoxButtons.OK, MessageBoxIcon.Stop); 
           Console.Write("Press any key when authorization attempt has succeeded"); 
           Console.Write("Getting access token..."); 
           AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); 
           oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; 
           Console.WriteLine("Done"); 
           ChangeTag("<DropBoxToken>", oauthAccessToken.Value + "," + oauthAccessToken.Secret); // update the xml file with the token.       
          } 
    
          IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); 
          DropboxLink shareableLink; 
          double filesNameLength = Math.Ceiling(Convert.ToDouble(filesNameLink.Length/2)); 
    
          // remove everything before the users special folder path including the dropbbox folder. 
          // then change all the switches to front from back for the web. 
          for (int i = 0; i < filesNameLength; i++) 
          { 
           filesNameLink[i, 1] = filesNameLink[i, 0]; 
           filesNameLink[i, 0] = Path.GetFileName(filesNameLink[i, 0]); 
           filesNameLink[i, 1] = filesNameLink[i, 1].Replace(dropboxRootDir, "").Replace("\\", "/"); 
           shareableLink = dropbox.GetShareableLinkAsync(filesNameLink[i, 1].Replace("\\", "/")).Result; 
           filesNameLink[i, 1] = shareableLink.Url; 
          } 
          // do something with the link(s). // 
          catch { } 
         } 
        } 
        catch { } 
    }