当前位置: 首页>>代码示例>>C#>>正文


C# BoxRequest.Payload方法代码示例

本文整理汇总了C#中BoxRequest.Payload方法的典型用法代码示例。如果您正苦于以下问题:C# BoxRequest.Payload方法的具体用法?C# BoxRequest.Payload怎么用?C# BoxRequest.Payload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BoxRequest的用法示例。


在下文中一共展示了BoxRequest.Payload方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Exchange

        /// <summary>
        /// Get a down scoped token.
        /// </summary>
        /// <returns>The down scoped access token.</returns>
        public string Exchange()
        {
            BoxRequest boxRequest = new BoxRequest(new Uri(Constants.BoxApiHostUriString), Constants.AuthTokenEndpointString)
                .Method(RequestMethod.Post)
                .Payload(Constants.RequestParameters.SubjectToken, token)
                .Payload(Constants.RequestParameters.SubjectTokenType, Constants.RequestParameters.AccessTokenTypeValue)
                .Payload(Constants.RequestParameters.Scope, scope)
                .Payload(Constants.RequestParameters.Resource, resourceUrl)
                .Payload(Constants.RequestParameters.GrantType, Constants.RequestParameters.TokenExchangeGrantTypeValue);

            if (actorToken != null)
            {
                boxRequest = boxRequest.Payload(Constants.RequestParameters.ActorToken, actorToken)
                    .Payload(Constants.RequestParameters.ActorTokenType, Constants.RequestParameters.IdTokenTypeValue);
            }

            var handler = new HttpRequestHandler();
            var converter = new BoxJsonConverter();
            var service = new BoxService(handler);

            IBoxResponse<OAuthSession> boxResponse = service.ToResponseAsync<OAuthSession>(boxRequest).Result;
            boxResponse.ParseResults(converter);

            return boxResponse.ResponseObject.AccessToken;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:29,代码来源:TokenExchange.cs

示例2: CopyAsync

        /// <summary>
        /// Used to create a copy of a file in another folder. The original version of the file will not be altered.
        /// </summary>
        /// <param name="fileRequest">BoxFileRequest object.</param>
        /// <param name="fields">Attribute(s) to include in the response.</param>
        /// <returns>
        /// A full file object is returned if the ID is valid and if the update is successful. 
        /// Errors can be thrown if the destination folder is invalid or if a file-name collision occurs. 
        /// </returns>
        public async Task<BoxFile> CopyAsync(BoxFileRequest fileRequest, List<string> fields = null)
        {
            fileRequest.ThrowIfNull("fileRequest");
            fileRequest.Id.ThrowIfNullOrWhiteSpace("fileRequest.Id");
            fileRequest.Parent.ThrowIfNull("fileRequest.Parent")
                .Id.ThrowIfNullOrWhiteSpace("fileRequest.Parent.Id");

            BoxRequest request = new BoxRequest(_config.FilesEndpointUri, string.Format(Constants.CopyPathString, fileRequest.Id))
                .Method(RequestMethod.Post)
                .Param(ParamFields, fields);

            fileRequest.Id = null; //file Id was used as a query parameter in this case
            request.Payload(_converter.Serialize(fileRequest));

            IBoxResponse<BoxFile> response = await ToResponseAsync<BoxFile>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:27,代码来源:BoxFilesManager.cs

示例3: RestoreTrashedFolderAsync

        /// <summary>
        /// Restores an item that has been moved to the trash. Default behavior is to restore the item to the folder it was in 
        /// before it was moved to the trash. If that parent folder no longer exists or if there is now an item with the same 
        /// name in that parent folder, the new parent folder and/or new name will need to be included in the request.
        /// </summary>
        /// <param name="folderRequest">BoxFolderRequest object (specify Parent.Id if you wish to restore to a different parent)</param>
        /// <param name="fields">Attribute(s) to include in the response</param>
        /// <returns>The full item will be returned if success. By default it is restored to the parent folder it was in before it was trashed.</returns>
        public async Task<BoxFolder> RestoreTrashedFolderAsync(BoxFolderRequest folderRequest, List<string> fields = null)
        {
            folderRequest.ThrowIfNull("folderRequest")
                .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id");
            
            BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, folderRequest.Id)
                    .Method(RequestMethod.Post)
                    .Param(ParamFields, fields);

            // ID shall not be used in request body it is used only as url attribute
            string oldId = folderRequest.Id;
            folderRequest.Id = null;

            request.Payload(_converter.Serialize(folderRequest));

            folderRequest.Id = oldId;

            IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
开发者ID:box,项目名称:box-windows-sdk-v2,代码行数:29,代码来源:BoxFoldersManager.cs


注:本文中的BoxRequest.Payload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。