ユーザーが Google ドライブ アカウントにファイルをアップロードできるようにするプログラムを作成しています。アップロード部分が機能しており、OAuth2 を使用しています。私が現在抱えている問題は、ユーザーのドライブ アカウントからフォルダーのリストを取得することです。
.setUserCredentials メソッドを使用してこれを行うはずのコードを見つけましたが、機能しません。
DocumentsService service1 = new DocumentsService("project");            
        service1.setUserCredentials("user","pass");
        FolderQuery query1 = new FolderQuery();
        // Make a request to the API and get all documents.
        DocumentsFeed feed = service1.Query(query1);
        // Iterate through all of the documents returned
        foreach (DocumentEntry entry in feed.Entries)
        {
            var blech = entry.Title.Text;
        }
何も返されません。理想的には、これを行うために OAuth2 を使用したいと考えています。認証トークンを設定しようとして、次のコードを試してみましたが、常にアクセスが拒否されます。
String CLIENT_ID = "clientid";
String CLIENT_SECRET = "secretid";
var docprovider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
var docstate = GetDocAuthentication(docprovider);
DocumentsService service1 = new DocumentsService("project");
service1.SetAuthenticationToken(docstate.RefreshToken);
FolderQuery query1 = new FolderQuery();
DocumentsFeed feed = service1.Query(query1); //get error here
        // Iterate through all of the documents returned
        foreach (DocumentEntry entry in feed.Entries)
        {
            // Print the title of this document to the screen
            var blech = entry.Title.Text;
        }
..
    private static IAuthorizationState GetDocAuthentication(NativeApplicationClient client)
    {
        const string STORAGE = "storagestring";
        const string KEY = "keystring";
        string scope = "https://docs.google.com/feeds/default/private/full/-/folder";            
        // Check if there is a cached refresh token available.
        IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY);
        if (state != null)
        {
            try
            {
                client.RefreshToken(state);
                return state; // Yes - we are done.
            }
            catch (DotNetOpenAuth.Messaging.ProtocolException ex)
            {
            }
        }
        // Retrieve the authorization from the user.
        state = AuthorizationMgr.RequestNativeAuthorization(client, scope);
        AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state);
        return state;
    }
具体的には、「リクエストの実行に失敗しました: https://docs.google.com/feeds/default/private/full/-/folder - リモート サーバーがエラーを返しました: (401) Unauthorized」というメッセージが表示されます。
私も試しました:
var docauth = new OAuth2Authenticator<NativeApplicationClient>(docprovider, GetDocAuthentication);
DocumentsService service1 = new DocumentsService("project");
service1.SetAuthenticationToken(docauth.State.AccessToken);
しかし、「状態」は常に null なので、null オブジェクト エラーが発生します。私は何を間違っていますか、これはどのように行われますか?