重命名IOS box v2 api中的文件夹
以下是box developer站点中给出的程序重命名IOS box v2 api中的文件夹,ios,file-io,box-api,Ios,File Io,Box Api,以下是box developer站点中给出的程序 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 objec
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"
}
我找到了解决办法。我发布了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"];