2017-02-07 2 views
0

Dropbox API를 사용하여 파일 업로드, 다운로드, 삭제 등의 작업을 수행하는 클래스를 작성했습니다. 내 자신의 액세스 토큰을 사용하고 있기 때문에 상당히 잘 작동했지만 다른 사용자를 등록해야하지만 "큰"문제가 하나만 나타납니다. 액세스 토큰을 검색하는 중입니다.Dropbox API를 사용하여 Windows Form의 Dropbox 액세스 토큰

1- 리디렉션 URI? 나는 왜 내가 이것을 필요로하는지 의심하기 시작했다. 마지막으로이 URI (https://www.dropbox.com/1/oauth2/redirect_receiver)를 사용했습니다. "The redirect URI you use doesn't really matter" 물론 Dropbox의 내 응용 프로그램 구성에이 파일을 포함 시켰습니다.

2 .- 내가 사용자의 계정에 도달 (I 사용자의 수가 증가 볼 수 있고 나는 앱이 사용자의 계정에 액세스 할 수 있습니다 참조하십시오.

3 .-을 내가 변수를 검사하려면 코드에 브레이크 포인트를 위해 DropboxOAuth2Helper.ParseTokenFragment을 적용하지만 난 거기에 더 성공이 없습니다

이 내 코드이지만,에하여 시도의 캐치가 걸리면 어디 전에 같은 경우.

string AccessToken; 
const string AppKey = "theOneAtmyAppConfigOnDropbox"; 
const string redirectUrl = "https://www.dropbox.com/1/oauth2/redirect_receiver"; 
string oauthUrl = 
    [email protected]"https://www.dropbox.com/1/oauth2/authorize?response_type=token&redirect_uri={redirectUrl}&client_id={AppKey}"; 

private string oauth2State; 
private bool Result; 

public Form1() 
{ 
    InitializeComponent(); 
} 

private void Form1_Load(object sender, EventArgs e) 
{ 
    Start(AppKey, webBrowser1); 

    webBrowser1.Navigating += Browser_Navigating; 
} 

private void Start(string appKey, WebBrowser w) 
{ 
    this.oauth2State = Guid.NewGuid().ToString("N"); 
    Uri authorizeUri = DropboxOAuth2Helper.GetAuthorizeUri(OauthResponseType.Token, appKey, redirectUrl, state: oauth2State); 
    w.Navigate(authorizeUri); 
} 

private void Browser_Navigating(object sender, WebBrowserNavigatingEventArgs e) 
{ 
    if (!e.Url.ToString().StartsWith(redirectUrl, StringComparison.InvariantCultureIgnoreCase)) 
    { 

     // we need to ignore all navigation that isn't to the redirect uri. 
     return; 
    } 

    try 
    { 
     OAuth2Response result = DropboxOAuth2Helper.ParseTokenFragment(e.Url); 
     if (result.State != this.oauth2State) 
     { 
      // The state in the response doesn't match the state in the request. 
      return; 
     } 

     this.AccessToken = result.AccessToken; 
     this.Result = true; 
    } 
    catch (ArgumentException) 
    { 
     // There was an error in the URI passed to ParseTokenFragment 
    } 
    finally 
    { 
     e.Cancel = true; 
     this.Close(); 
    } 
} 

내가 ' 있었어. 이것을 몇 시간 동안 싸우고 나는이 시점에서 약간 흐려지기 시작합니다.

This은 내가 사용한 튜토리얼이지만 앞으로 나아갈 생각이 아닙니다. 나는 정말 어떤 도움을 주셔서 감사합니다!

편집 : 마침내 앞으로 몇 가지 조치를 취했습니다.

Uri authorizeUri2 = DropboxOAuth2Helper.GetAuthorizeUri(appKey); 

지금 생성 된 액세스 토큰을 WebClient에 표시하고 있습니다! 나쁜 부분은 그것을 얻으 려 할 때 나온다. (if가 if 내부에 들어간다.) 나는 사용자에게 허가를 요청할 때마다 생성되기 때문에, 그것은 지나치다.

EDIT 2 : 브라우저에서 생성되는 토큰이 어떻게 든 잘못된 형식임을 나타 냈습니다. 내가 디버깅있을 때 수동으로이 hardcored 변경하려고하고 나는 AuthException DropboxClient 객체를 생성 예외가 :(도대체! 그렉 언급 한 바와 같이

+0

[참조 용 교차 링크 : https : //www.dropboxforum .com/t5/API 지원/Facing-Problems-Access-Token-from-a-User-on-Windows/mp/205702 # M9950] – Greg

답변

0

이 솔루션은 을 Browser_Navigated 이벤트를 사용하고 있었다. 외모를 내 Visual Studio (2015) 임베디드 IE 버전과 마찬가지로 리디렉션 인 경우 BrowserNavigating 이벤트가 실행되지 않습니다.