Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. btn2.setOnClickListener(new OnClickListener() {
  2.  
  3. @Override
  4. public void onClick(View v) {
  5. // TODO Auto-generated method stub
  6.  
  7. String title = "This is facebook Data";
  8.  
  9. try {
  10. Intent i = new Intent(Intent.ACTION_VIEW);
  11.  
  12. i.setData(Uri.parse("https://m.facebook.com/sharer.php?u="
  13. + "www.facebook.com" + "&t=" + title + "&_rdr"));
  14.  
  15. startActivity(i);
  16. } catch (Exception e) {
  17. e.printStackTrace();
  18. }
  19. }
  20. });
  21.  
  22. private void fbImageSubmit(Facebook fb, String imageurl, String caption, String description, String name, String linkurl)
  23. {
  24. if(fb != null)
  25. {
  26. if(fb.isSessionValid())
  27. {
  28. Bundle b = new Bundle();
  29. b.putString("picture", imageurl);
  30. b.putString("caption",caption);
  31. b.putString("description",description );
  32. b.putString("name",name);
  33. b.putString("link",linkurl);
  34. try {
  35. String strRet = "";
  36. strRet = fb.request("/me/feed",b,"POST");
  37. JSONObject json;
  38. try {
  39. json = Util.parseJson(strRet);
  40. if(!json.isNull("id"))
  41. {
  42. Log.i("Facebook", "Image link submitted.");
  43. }
  44. else
  45. {
  46. Log.e("Facebook","Error: " + strRet);
  47. }
  48. } catch (FacebookError e) {
  49. Log.e("Facebook","Error: " + e.getMessage());
  50. }
  51. } catch (Exception e) {
  52. Log.e("Facebook", "Error: " + e.getMessage());
  53. }
  54. }
  55. }
  56. }
  57.  
  58. facebook.authorize(FbdemoActivity.this, new String[]{ "user_photos,publish_checkins,publish_actions,publish_stream"},new DialogListener() {
  59. @Override
  60. public void onComplete(Bundle values) {
  61.  
  62.  
  63.  
  64. }
  65.  
  66. @Override
  67. public void onFacebookError(FacebookError error) {
  68. }
  69.  
  70. @Override
  71. public void onError(DialogError e) {
  72. }
  73.  
  74. @Override
  75. public void onCancel() {
  76. }
  77. });
  78.  
  79.  
  80. public void postImageonWall() {
  81.  
  82. byte[] data = null;
  83.  
  84. Bitmap bi = BitmapFactory.decodeFile("/sdcard/viewitems.png");
  85. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  86. bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
  87. data = baos.toByteArray();
  88.  
  89.  
  90. Bundle params = new Bundle();
  91. params.putString(Facebook.TOKEN, facebook.getAccessToken());
  92. params.putString("method", "photos.upload");
  93. params.putByteArray("picture", data);
  94.  
  95. AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
  96. mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
  97.  
  98.  
  99. }
  100.  
  101.  
  102. public class SampleUploadListener extends BaseRequestListener {
  103.  
  104. public void onComplete(final String response, final Object state) {
  105. try {
  106. // process the response here: (executed in background thread)
  107. Log.d("Facebook-Example", "Response: " + response.toString());
  108. JSONObject json = Util.parseJson(response);
  109. final String src = json.getString("src");
  110.  
  111. // then post the processed result back to the UI thread
  112. // if we do not do this, an runtime exception will be generated
  113. // e.g. "CalledFromWrongThreadException: Only the original
  114. // thread that created a view hierarchy can touch its views."
  115.  
  116. } catch (JSONException e) {
  117. Log.w("Facebook-Example", "JSON Error in response");
  118. } catch (FacebookError e) {
  119. Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
  120. }
  121. }
  122.  
  123. @Override
  124. public void onFacebookError(FacebookError e, Object state) {
  125. // TODO Auto-generated method stub
  126.  
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement