Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Box API更新电子邮件别名问题_Java_Apache Httpclient 4.x_Box Api - Fatal编程技术网

Java Box API更新电子邮件别名问题

Java Box API更新电子邮件别名问题,java,apache-httpclient-4.x,box-api,Java,Apache Httpclient 4.x,Box Api,我正在尝试更新不同用户的电子邮件别名。我能够进行身份验证,获取代码,然后获取访问令牌。我将HTTP POST请求中的访问令牌作为头发送。我正在使用Java和apachehttpclient进行RESTful调用。下面是代码片段(仅显示相关代码) if(httpClient!=null){ 字符串apirl=getapirl(); apiURL=MessageFormat.format(apiURL,firstname)。lastname@company.com"); //APIRL=https:

我正在尝试更新不同用户的电子邮件别名。我能够进行身份验证,获取代码,然后获取访问令牌。我将HTTP POST请求中的访问令牌作为头发送。我正在使用Java和apachehttpclient进行RESTful调用。下面是代码片段(仅显示相关代码)

if(httpClient!=null){
字符串apirl=getapirl();
apiURL=MessageFormat.format(apiURL,firstname)。lastname@company.com");
//APIRL=https://api.box.com/2.0/users/firstname.lastname@company.com/email\u别名
//名字。lastname@company.com是否存在于Box帐户中
HttpPost=新的HttpPost(apiURL);
post.addHeader(“授权”、“承载人”+访问令牌);
List nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“电子邮件”)updateemail@company.com"));
setEntity(新的UrlEncodedFormEntity(nameValuePairs,Charset.defaultCharset());
HttpEntity=post.getEntity();
ResponseHandler ResponseHandler=新BasicResponseHandler();
字符串responseFromBox=httpClient.execute(post,responseHandler);
writeResponse(response,responseFromBox);
if(responseFromBox!=null){
if(logger.isDebugEnabled()){
debug(“apirl-->”+apirl);
logger.debug(responseFromBox);
}
}
}
问题是,我得到的响应是一些HTML代码,上面写着“您正在查看的页面已过期。请返回并重试您的请求。”我正在等待一些JSON字符串

我做的不对吗?在Post请求中,我没有发送电子邮件地址,而是使用了用户id。但我得到了相同的错误

事实上,当我尝试使用HTTP GET请求获取用户的电子邮件别名时,我得到一个错误“Not Found”。用户确实存在。我有一个管理员控制。我能看见他们

谢谢
Raj

首先尝试登录/users以获取企业中所有用户的数组。这对你有用吗?如果没有,你能做一个关于/users/me的测试吗?如果您不能获得前者,那么您的API密钥可能没有“管理企业”授权设置。您必须在应用程序管理中进行设置,在其中设置OAuth2回调URL

不确定为什么要恢复HTML。这通常只发生在格式错误的请求上,而我们的服务器甚至无法解析这些请求,就像您输入了错误的URL一样

提醒一下,OAuth2URL与API URL不同。第一是。。。。第二是


至于设置电子邮件别名,一旦您知道要为其设置别名的用户的ID,这是完全可能的。文档是

我使用的是NameValuePair,而不是预期的JSON字符串。因此,我删除了以下内容

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();            
nameValuePairs.add(new BasicNameValuePair("email", "updateemail@company.com"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Charset.defaultCharset()));

然后事情开始发生了

谢谢彼得的回复。我能够通过Java代码检索所有用户以及我的信息。当我在box.com上创建应用程序时,我确实选中了“管理企业”选项。是的,我的网址是。。。更新电子邮件别名也不适用于邮递员。
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();            
nameValuePairs.add(new BasicNameValuePair("email", "updateemail@company.com"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Charset.defaultCharset()));
String json = "{\"email\":\"firstname.lastname@company.com\"}";
StringEntity entity = new StringEntity(json, Charset.defaultCharset());
post.setEntity(entity);