-2

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.

Raptor
  • 53,206
  • 45
  • 230
  • 366
  • what i mean is, from your code, a number of things could go wrong. It is not possible to answer your question as it is. You have to A/ post a stacktrace if there is one. B/ post the errors you receive from yammer if such. – njzk2 May 24 '13 at 08:16
  • i am not getting any error, when i do loging in my account from my app through this code it should post a data on my wall but it is not posting right now... if you have any other code plz give me... – Rahul Pawaiya May 24 '13 at 08:21
  • what is the answer from the server ? (and you can't setHeader on a response, the header is set by the server, because, like, **he** knows what he put in the response, not you) – njzk2 May 24 '13 at 08:24
  • and you should test response.getStatusLine().getStatusCode(). – njzk2 May 24 '13 at 08:25
  • response.getStatusLine().getStatusCode() giving me error that getStatusLine() is undefined. – Rahul Pawaiya May 24 '13 at 08:59
  • when I say response, I of course mean the response you get in your Handler, the HttpResponse instance, not the String. – njzk2 May 24 '13 at 09:11
  • hey i am getting status code 400..it means what.. – Rahul Pawaiya May 24 '13 at 09:41
  • it means ... http://en.wikipedia.org/wiki/List_of_HTTP_status_codes your request is invalid. there may still be a response (the string, this time) that may provide some insight. 400 is a very generic error usually meaning that there is something unexpected about your query. – njzk2 May 24 '13 at 09:43
  • so how can i resolve it..?? – Rahul Pawaiya May 24 '13 at 09:48
  • post the log from `System.out.println("response---->>"+response);` – njzk2 May 24 '13 at 09:48
  • 05-24 09:39:40.558: I/System.out(5481): response---->>{"body":["Please include a message"]} – Rahul Pawaiya May 24 '13 at 09:51
  • Apparently yammer thinks you didn't include a message. – njzk2 May 24 '13 at 10:00
  • but i have include message you saw that post.setEntity(new StringEntity("hi this is deloitte game.")); – Rahul Pawaiya May 24 '13 at 10:03
  • plz give me any solution ...... – Rahul Pawaiya May 24 '13 at 10:04
  • @RahulPawaiya Could you please let me know how did you integrate Yammmer into your Android app? I am not able to find any documentation regarding the same. I have no idea from where to start. Any link to it is greatly appreciated. – SKP Mar 22 '17 at 16:37

1 Answers1

0

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()));
njzk2
  • 38,969
  • 7
  • 69
  • 107
  • i have included your code in my class but i am still getting same response 05-24 10:17:07.048: I/System.out(6383): response---->>{"body":["Please include a message"]} – Rahul Pawaiya May 24 '13 at 10:19
  • i just found in the documentation `POST messages are form encoded.`. So the first solution I gave should work. You may need to change the request content-type to match this. Also, I'm not sure you need the secret and the id one you have the token – njzk2 May 24 '13 at 12:38
  • Thanks @njzk2 i have solved my issue of yammer , the problem was set header as you told. i have change it and it worked... thanks once again... – Rahul Pawaiya May 24 '13 at 14:43