Android Facebook Graph API

Does anyone have an example of using the Android Graph API?

I'm stuck in the basics, for example by posting text on a wall on Facebook.

I am using Android SDK for Android. Here is what I still have:

Bundle params = new Bundle(); params.putString("message", "picture caption"); AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook); mAsyncRunner.request("me/feed", params, "POST", new RequestListener() { @Override public void onMalformedURLException(MalformedURLException e, Object state) { // TODO Auto-generated method stub } @Override public void onIOException(IOException e, Object state) { // TODO Auto-generated method stub } @Override public void onFileNotFoundException(FileNotFoundException e, Object state) { // TODO Auto-generated method stub } @Override public void onFacebookError(FacebookError e, Object state) { // TODO Auto-generated method stub } @Override public void onComplete(String response, Object state) { // TODO Auto-generated method stub } }, "foo"); 

Nothing happens and my Logcat says:

 03-02 22:10:02.973: WARN/Bundle(1930): Key message expected byte[] but value was a java.lang.String. The default value <null> was returned. 03-02 22:10:02.983: WARN/Bundle(1930): Attempt to cast generated internal exception: 03-02 22:10:02.983: WARN/Bundle(1930): java.lang.ClassCastException: java.lang.String 03-02 22:10:02.983: WARN/Bundle(1930): at android.os.Bundle.getByteArray(Bundle.java:1305) 03-02 22:10:02.983: WARN/Bundle(1930): at com.facebook.android.Util.encodePostBody(Util.java:63) 03-02 22:10:02.983: WARN/Bundle(1930): at com.facebook.android.Util.openUrl(Util.java:182) 03-02 22:10:02.983: WARN/Bundle(1930): at com.facebook.android.Facebook.request(Facebook.java:559) 03-02 22:10:02.983: WARN/Bundle(1930): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253) 
+4
source share
3 answers
+1
source

try it

 Bundle params = new Bundle(); params.putString(Facebook.TOKEN, token); params.putString("message", "graph api"); mAsyncRunner.request("/me/feed", params,"POST", new SampleUploadListener(),null); 

you can get access token using

  token = mFacebook.getAccessToken(); 
+2
source

You can do this as: - give a description in the bundle message, and if you want to share some image from the server, you can provide a link as shown below.

  Bundle params = new Bundle(); params.putString("message", "description"); params.putString("link","your image url" ); new GraphRequest( AccessToken.getCurrentAccessToken(), "me/feed", params, HttpMethod.POST, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { Log.d(TAG, "" + response.toString()); try { JSONObject jsonObject = new JSONObject(response.getRawResponse()); if (jsonObject != null) { String postId = jsonObject.getString("id"); if (postId != null && !postId.equalsIgnoreCase("")) { hideProgressDialog(); Log.d("postId", "" + postId); } else { hideProgressDialog(); Utils.showToast(getActivity(), getResources().getString(R.string.txt_try_again)); } } else { hideProgressDialog(); Utils.showToast(getActivity(), getResources().getString(R.string.txt_try_again)); } } catch (JSONException e) { hideProgressDialog(); e.printStackTrace(); } catch (Throwable e) { hideProgressDialog(); e.printStackTrace(); } } }).executeAsync(); 
+2
source

Source: https://habr.com/ru/post/1342049/


All Articles