以下框开发者网站中给出的步骤。
curl https://api.box.com/2.0/folders/FOLDER_ID \
-H "Authorization: Bearer ACCESS_TOKEN" \
-d '{"name":"New Folder Name!"}' \
-X PUT
这是我的代码:
NSString *newDirectoryName;
NSString *str;
NSString*fid = [[boxFilePathsArray objectAtIndex:0] objectForKey:@"folderId"];
NSString * type = [[boxFilePathsArray objectAtIndex:0]objectForKey:@"type"];
NSString * str_access_token = [[arrUseraccounts objectAtIndex:[DropboxDownloadFileViewControlller getSharedInstance].index] objectForKey:@"acces_token"];
if ([type isEqualToString:@"folder"])
{
newDirectoryName =tempString;
str = [NSString stringWithFormat:@"https://api.box.com/2.0/folders/%@?access_token=%@",fid,str_access_token];
}
else
{
newDirectoryName = [NSString stringWithFormat:@"%@.pdf",tempString];
str = [NSString stringWithFormat:@"https://api.box.com/2.0/files/%@?access_token=%@",fid,str_access_token];
}
ASIFormDataRequest *postParams = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:str]];
[postParams setPostValue:newDirectoryName forKey:@"name"];
[postParams setRequestMethod:@"PUT"];
[postParams startAsynchronous];
postParams.delegate = self ;
postParams.userInfo = [NSDictionary dictionaryWithObject:@"RenameFolder" forKey:@"id"];
我得到的回应是:
{
"status" : 400,
"help_url" : "http:\/\/developers.box.com\/docs\/#errors",
"code" : "bad_request",
"request_id" : "169126257953f1ed709ab32",
"context_info" : {
"errors" : [
{
"name" : "entity-body",
"message" : "Invalid value 'name=dd'. Entity body should be a correctly nested resource attribute name\/value pair",
"reason" : "invalid_parameter"
}
]
},
"message" : "Bad Request",
"type" : "error"
}
答案 0 :(得分:0)
我得到了解决方案。我发布了JSON正文。这是我的代码。
NSString *newDirectoryName;
NSString *str;
NSString*fid = [[boxFilePathsArray objectAtIndex:0] objectForKey:@"folderId"];
NSString * type = [[boxFilePathsArray objectAtIndex:0]objectForKey:@"type"];
NSString * str_access_token = [[arrUseraccounts objectAtIndex:[DropboxDownloadFileViewControlller getSharedInstance].index] objectForKey:@"acces_token"];
if ([type isEqualToString:@"folder"])
{
newDirectoryName =tempString;
str = [NSString stringWithFormat:@"https://api.box.com/2.0/folders/%@?access_token=%@",fid,str_access_token];
}
else
{
newDirectoryName = [NSString stringWithFormat:@"%@.pdf",tempString];
str = [NSString stringWithFormat:@"https://api.box.com/2.0/files/%@?access_token=%@",fid,str_access_token];
}
NSDictionary *cid = [[NSDictionary alloc] initWithObjectsAndKeys:newDirectoryName,@"name", nil];
NSError *error;
NSData *postData = [NSJSONSerialization dataWithJSONObject:cid options:0 error:&error];
NSMutableData *data = [[NSMutableData alloc] initWithData:postData];
ASIFormDataRequest *postParams = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:str]];
//[postParams setPostValue:newDirectoryName forKey:@"name"];
[postParams setPostBody:data];
[postParams setRequestMethod:@"PUT"];
[postParams startAsynchronous];
postParams.delegate = self ;
postParams.userInfo = [NSDictionary dictionaryWithObject:@"RenameFolder" forKey:@"id"];