Какой простой способ опубликовать фотографию на FB с использованием аутентификации по умолчанию и получить сообщение о том, что фотография опубликована - PullRequest
1 голос
/ 02 декабря 2011

Я хочу опубликовать фотографию на FB с помощью Auth.Я хочу любой простой демонстрационный пример, который может помочь мне опубликовать фотографию на FB.Может ли Anybudy помочь мне в этом?Спасибо.

С ответом Hardik я получил следующее исключение:

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)

Ответы [ 3 ]

1 голос
/ 02 декабря 2011

Вы можете сделать это, используя Graph API FaceBook.см. эту ссылку ..

Загрузка изображений в Facebook с помощью Graph API с Android SDK

1 голос
/ 02 декабря 2011

привет первый Загрузить Facebook SDK ..

Facebook SDK

затем в методе Создать

// для 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();

        }
    });

Способ загрузки фото

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);
}
1 голос
/ 02 декабря 2011

Загрузка фотографии в альбом приложения

Использование 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>';
  }
    ?>

Пример ответа

    {
       "id": "1001207389476"
    }
...