Вопрос

I have problem with Yammer Intregration in Android, i am unable to authenticate my app with Yammer so i cannot post my data on Yammer through my Android app.

JSONObject job = new JSONObject();
/*ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair("score", score));          // user : User name from Text Field
*/
HttpPost post = new HttpPost("https://www.yammer.com/api/v1/messages.json?client_id=JV8Vr6vYaF0RdyVnLKhnRg&client_secret=zACHEVUnUKaRD58Ho5MvnSjvRZaadNqpCOWirc9I8SiA&access_token="+tokens[1]); 
System.out.println("tokens[1]----------.>>>>>"+tokens[1]);

post.setHeader("Content-Type", "text/json; charset=utf-8"); // Header
            // for
            // HttpPost
            ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
                public String handleResponse(HttpResponse response) // Header
                // for
                // HttpResponse
                        throws ClientProtocolException, IOException {
                    response.setHeader("Content-Type", "charset=utf-8");
                    HttpEntity entity = response.getEntity();
                    StringBuffer outString = new StringBuffer();
                    outString.append(EntityUtils.toString(entity));
                    return outString.toString();
                }
            };
            try {
                System.out.println("hi this is deloitte game.");
                post.setEntity(new StringEntity("hi this is deloitte game."));
                DefaultHttpClient httpclient = new DefaultHttpClient();
                String response = httpclient.execute(post, responseHandler);
                System.out.println("response---->>"+response);
                //job = new JSONObject(response);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }*

i have used these code for yammer intregration ,in this code i have used post method to post the data on yammer but not able to post on yammer wall.

Это было полезно?

Решение

According to Yammer documentation https://developer.yammer.com/restapi/#rest-messages

You are supposed to pass parameters to the request, not a plain string in your post. (Otherwise, how do you expect Yammer to know what is the body, what are the topics, the attachements ...)

Typically, this is done using a UrlEncodedFormEntity with a list of NameValuePair.

Your entity should look like this :

List<NameValuePair> values = new ArrayList<NameValuePair>();
values.add(new BasicNameValuePair("body", "hi this is deloitte game.");
HttpEntity postEntity = new UrlEncodedFormEntity(values);
post.setEntity(postEntity);

It is possible that the service is actually expecting a JSON input, in which case it is even simple.

edit

If it is in json, i could look like :

JSONObject jsonObject = new JSONObject();
jsonObject.put("body", "hi this is a body");
post.setEntity(new StringEntity(jsonObject.toString()));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top