尝试通过REST API添加新联系人时出现问题。 [英] Problem while trying to add a new Contact via REST API.

查看:61
本文介绍了尝试通过REST API添加新联系人时出现问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过REST API添加新联系人。 (因为它不可能通过MSN的XMPP接口。)但是我收到HTTP 415错误。我正在发送以下示例请求。有在请求???

I'm trying to add new contact via REST API. (Because it's not possible via XMPP interface of MSN.) But i'm getting HTTP 415 error. I'm sending the following sample request . Is there problem in the request ???

我的示例Java代码,用于为我的Oauth用户添加新联系人: 

My Sample Java code for adding new contact for my Oauth user : 

..

..

 String accessToken = "BLABLABLABLABLA";
            String msnRestApi = "https://apis.live.net/v5.0/me?" + "access_token=" + accessToken;

            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost postRequest = new HttpPost(msnRestApi);

            StringEntity input = new StringEntity(mapper.writeValueAsString(jsonContact));
            input.setContentType("application/json");
            postRequest.setEntity(input);

            HttpResponse response = httpClient.execute(postRequest);

            if (response.getStatusLine().getStatusCode() != 201) {
                throw new RuntimeException("Failed : HTTP error code : "
                        + response.getStatusLine().getStatusCode());
            }

            BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

            String output;
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {
                System.out.println(output);
            }

            httpClient.getConnectionManager().shutdown();

推荐答案

直接,我注意到你的路径是 /v5.0/me /?=的access_token YOUR_ACCESS_TOKEN 。它应该是
/v5.0/me/contacts?access_token=YOUR_ACCESS_TOKEN 。有关详细信息,请参阅
联系人帮助主题。

Straight away, I noticed your path is /v5.0/me/?access_token=YOUR_ACCESS_TOKEN. It should be /v5.0/me/contacts?access_token=YOUR_ACCESS_TOKEN. For more info, see the Contacts Help topic.

Paul

Live Connect开发人员文档团队

Paul
Live Connect developer documentation team


这篇关于尝试通过REST API添加新联系人时出现问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆