代码之家  ›  专栏  ›  技术社区  ›  sunil

重命名IOS box v2 api中的文件夹

  •  0
  • sunil  · 技术社区  · 11 年前

    以下是开发人员现场提供的程序。

    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"
    }
    
    1 回复  |  直到 11 年前
        1
  •  0
  •   modusCell    11 年前

    我找到了解决方案。我发布了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"];