Which is easy technique to Post Photo on FB with using the default auth and get message that the Photo is Posted

I want to Post the Photo on to the FB with Using Auth. I want any Easy Demo Example that can Help me to Post the Photo On FB. Can Anybudy Help me for that ? Thanks.

With Hardik Answer i got Exception like that:

12-02 14:29:42.820: WARN/Bundle(318): Key access_token expected byte[] but value was a java.lang.String.  The default value <null> was returned.
12-02 14:29:42.850: WARN/Bundle(318): Attempt to cast generated internal exception:
12-02 14:29:42.850: WARN/Bundle(318): java.lang.ClassCastException: java.lang.String
12-02 14:29:42.850: WARN/Bundle(318):     at android.os.Bundle.getByteArray(Bundle.java:1305)
12-02 14:29:42.850: WARN/Bundle(318):     at com.facebook.android.Util.openUrl(Util.java:155)
12-02 14:29:42.850: WARN/Bundle(318):     at com.facebook.android.Facebook.request(Facebook.java:563)
12-02 14:29:42.850: WARN/Bundle(318):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
12-02 14:29:42.850: WARN/Bundle(318): Key method expected byte[] but value was a java.lang.String.  The default value <null> was returned.
12-02 14:29:42.860: WARN/Bundle(318): Attempt to cast generated internal exception:
12-02 14:29:42.860: WARN/Bundle(318): java.lang.ClassCastException: java.lang.String
12-02 14:29:42.860: WARN/Bundle(318):     at android.os.Bundle.getByteArray(Bundle.java:1305)
12-02 14:29:42.860: WARN/Bundle(318):     at com.facebook.android.Util.openUrl(Util.java:155)
12-02 14:29:42.860: WARN/Bundle(318):     at com.facebook.android.Facebook.request(Facebook.java:563)
12-02 14:29:42.860: WARN/Bundle(318):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
12-02 14:29:42.900: WARN/Bundle(318): Key format expected byte[] but value was a java.lang.String.  The default value <null> was returned.
12-02 14:29:42.910: WARN/Bundle(318): Attempt to cast generated internal exception:
12-02 14:29:42.910: WARN/Bundle(318): java.lang.ClassCastException: java.lang.String
12-02 14:29:42.910: WARN/Bundle(318):     at android.os.Bundle.getByteArray(Bundle.java:1305)
12-02 14:29:42.910: WARN/Bundle(318):     at com.facebook.android.Util.openUrl(Util.java:155)
12-02 14:29:42.910: WARN/Bundle(318):     at com.facebook.android.Facebook.request(Facebook.java:563)
12-02 14:29:42.910: WARN/Bundle(318):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
12-02 14:29:44.560: INFO/global(318): Default buffer size used in BufferedOutputStream constructor. It would be better to be explicit if an 8k buffer is required.
12-02 14:29:44.560: WARN/Bundle(318): Key access_token expected byte[] but value was a java.lang.String.  The default value <null> was returned.
12-02 14:29:44.571: WARN/Bundle(318): Attempt to cast generated internal exception:
12-02 14:29:44.571: WARN/Bundle(318): java.lang.ClassCastException: java.lang.String
12-02 14:29:44.571: WARN/Bundle(318):     at android.os.Bundle.getByteArray(Bundle.java:1305)
12-02 14:29:44.571: WARN/Bundle(318):     at com.facebook.android.Util.encodePostBody(Util.java:63)
12-02 14:29:44.571: WARN/Bundle(318):     at com.facebook.android.Util.openUrl(Util.java:182)
12-02 14:29:44.571: WARN/Bundle(318):     at com.facebook.android.Facebook.request(Facebook.java:563)
12-02 14:29:44.571: WARN/Bundle(318):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
12-02 14:29:44.571: WARN/Bundle(318): Key method expected byte[] but value was a java.lang.String.  The default value <null> was returned.
12-02 14:29:44.580: WARN/Bundle(318): Attempt to cast generated internal exception:
12-02 14:29:44.580: WARN/Bundle(318): java.lang.ClassCastException: java.lang.String
12-02 14:29:44.580: WARN/Bundle(318):     at android.os.Bundle.getByteArray(Bundle.java:1305)
12-02 14:29:44.580: WARN/Bundle(318):     at com.facebook.android.Util.encodePostBody(Util.java:63)
12-02 14:29:44.580: WARN/Bundle(318):     at com.facebook.android.Util.openUrl(Util.java:182)
12-02 14:29:44.580: WARN/Bundle(318):     at com.facebook.android.Facebook.request(Facebook.java:563)
12-02 14:29:44.580: WARN/Bundle(318):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
12-02 14:29:44.613: WARN/Bundle(318): Key format expected byte[] but value was a java.lang.String.  The default value <null> was returned.
12-02 14:29:44.650: WARN/Bundle(318): Attempt to cast generated internal exception:
12-02 14:29:44.650: WARN/Bundle(318): java.lang.ClassCastException: java.lang.String
12-02 14:29:44.650: WARN/Bundle(318):     at android.os.Bundle.getByteArray(Bundle.java:1305)
12-02 14:29:44.650: WARN/Bundle(318):     at com.facebook.android.Util.encodePostBody(Util.java:63)
12-02 14:29:44.650: WARN/Bundle(318):     at com.facebook.android.Util.openUrl(Util.java:182)
12-02 14:29:44.650: WARN/Bundle(318):     at com.facebook.android.Facebook.request(Facebook.java:563)
12-02 14:29:44.650: WARN/Bundle(318):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)

Answers


hi first Download Facebook SDK..

Facebook SDK

then in Oncreate method

//for Authonticaion

public class FacebollAppforPhotoUpload extends Activity {

 //------------------FB-------------------------


Facebook facebook = new Facebook("APP_KEY");
String permissions[] = {""};
 String statusString = "";

 //---------------------------------------------


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);




    statusString="testing Post For Application Development";


    setContentView(R.layout.main);

     facebook.authorize(this, permissions, new DialogListener() {
        @Override
        public void onComplete(Bundle values) {


        //  updateStatus(values.getString(Facebook.TOKEN));
            uploadphoto(values.getString(Facebook.TOKEN));

            finish();

        }


        @Override
        public void onFacebookError(FacebookError error) {}

        @Override
        public void onError(DialogError e) {}

        @Override
        public void onCancel() {

            finish();

        }
    });

Phhot upload method

public void uploadphoto(String accessToken)
{
    byte[] data = null;

    ContentResolver cr = FacebollAppforPhotoUpload.this.getContentResolver();
   // InputStream fis = cr.openInputStream(localSnapshotUri);
    Bitmap bi = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    data = baos.toByteArray();    



    Bundle params = new Bundle();
    params.putString("method", "photos.upload");
    params.putByteArray("picture", data);

    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    mAsyncRunner.request(null, params, "POST", new RequestListener(){

        @Override
        public void onComplete(String response, 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 onMalformedURLException(MalformedURLException e,
                Object state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFacebookError(FacebookError e, Object state) {
            // TODO Auto-generated method stub

        }},null);
}

Uploading a photo to the app’s album

Using PHP

    <?php
   $app_id = "YOUR_APP_ID";
   $app_secret = "YOUR_APP_SECRET";
   $post_login_url = "YOUR_POST_LOGIN_URL";

   $code = $_REQUEST["code"];

   //Obtain the access_token with publish_stream permission 
   if(empty($code)){ 
      $dialog_url= "http://www.facebook.com/dialog/oauth?"
       . "client_id=" .  $app_id 
       . "&redirect_uri=" . urlencode( $post_login_url)
       .  "&scope=publish_stream";
      echo("<script>top.location.href='" . $dialog_url 
      . "'</script>");
     }
    else {
      $token_url="https://graph.facebook.com/oauth/access_token?"
       . "client_id=" . $app_id 
       . "&redirect_uri=" . urlencode( $post_login_url)
       . "&client_secret=" . $app_secret
       . "&code=" . $code;
      $response = file_get_contents($token_url);
      $params = null;
      parse_str($response, $params);
      $access_token = $params['access_token'];

     // Show photo upload form to user and post to the Graph URL
     $graph_url= "https://graph.facebook.com/me/photos?"
     . "access_token=" .$access_token;

     echo '<html><body>';
     echo '<form enctype="multipart/form-data" action="'
     .$graph_url .' "method="POST">';
     echo 'Please choose a photo: ';
     echo '<input name="source" type="file"><br/><br/>';
     echo 'Say something about this photo: ';
     echo '<input name="message" 
         type="text" value=""><br/><br/>';
     echo '<input type="submit" value="Upload"/><br/>';
     echo '</form>';
     echo '</body></html>';
  }
    ?>

Example Response

    {
       "id": "1001207389476"
    }

You can do it using Graph API of FaceBook . see this link..

Uploading pictures to Facebook using Graph API with Android SDK


Need Your Help

Unable to shut down Neo4j Jetty server within Tomcat webapp

java tomcat neo4j jetty

Currently I am working on an webapp that utilizes Neo4j. Our app needs to be deployed in a Tomcat environment (customer requirement). We decided to embed Neo4j, because that way we can use the Neo4j

Official way to get RTSP URL of a youtube video

youtube-api

I understand that youtube provide player API's for android/IOS and web. However I would like to play youtube videos with in my application which is written in C++ using gstreamer. In order to strea...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.