Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- btn2.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- String title = "This is facebook Data";
- try {
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(Uri.parse("https://m.facebook.com/sharer.php?u="
- + "www.facebook.com" + "&t=" + title + "&_rdr"));
- startActivity(i);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- private void fbImageSubmit(Facebook fb, String imageurl, String caption, String description, String name, String linkurl)
- {
- if(fb != null)
- {
- if(fb.isSessionValid())
- {
- Bundle b = new Bundle();
- b.putString("picture", imageurl);
- b.putString("caption",caption);
- b.putString("description",description );
- b.putString("name",name);
- b.putString("link",linkurl);
- try {
- String strRet = "";
- strRet = fb.request("/me/feed",b,"POST");
- JSONObject json;
- try {
- json = Util.parseJson(strRet);
- if(!json.isNull("id"))
- {
- Log.i("Facebook", "Image link submitted.");
- }
- else
- {
- Log.e("Facebook","Error: " + strRet);
- }
- } catch (FacebookError e) {
- Log.e("Facebook","Error: " + e.getMessage());
- }
- } catch (Exception e) {
- Log.e("Facebook", "Error: " + e.getMessage());
- }
- }
- }
- }
- facebook.authorize(FbdemoActivity.this, new String[]{ "user_photos,publish_checkins,publish_actions,publish_stream"},new DialogListener() {
- @Override
- public void onComplete(Bundle values) {
- }
- @Override
- public void onFacebookError(FacebookError error) {
- }
- @Override
- public void onError(DialogError e) {
- }
- @Override
- public void onCancel() {
- }
- });
- public void postImageonWall() {
- byte[] data = null;
- Bitmap bi = BitmapFactory.decodeFile("/sdcard/viewitems.png");
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
- data = baos.toByteArray();
- Bundle params = new Bundle();
- params.putString(Facebook.TOKEN, facebook.getAccessToken());
- params.putString("method", "photos.upload");
- params.putByteArray("picture", data);
- AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
- mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
- }
- public class SampleUploadListener extends BaseRequestListener {
- public void onComplete(final String response, final Object state) {
- try {
- // process the response here: (executed in background thread)
- Log.d("Facebook-Example", "Response: " + response.toString());
- JSONObject json = Util.parseJson(response);
- final String src = json.getString("src");
- // then post the processed result back to the UI thread
- // if we do not do this, an runtime exception will be generated
- // e.g. "CalledFromWrongThreadException: Only the original
- // thread that created a view hierarchy can touch its views."
- } catch (JSONException e) {
- Log.w("Facebook-Example", "JSON Error in response");
- } catch (FacebookError e) {
- Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
- }
- }
- @Override
- public void onFacebookError(FacebookError e, Object state) {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement