-2

AndroidとFacebook SDKを使用してFacebookに画像とテキストを投稿する正しい方法を見つけるために、私はどこにでも探していました。このコードを取得してメッセージだけを投稿できますが、スクリーンショットを投稿しようとすると、null ポインター例外が発生します。私は他のスレッドから多くの異なるコード スニペットを試しましたが、どれもうまくいかないようです。私ができる最善のことは、メッセージではなく写真を壁に投稿するこのコードです。ここで何が間違っているのか教えてください。とても有難い。

View content = findViewById(R.id.row1);
        Log.d("captureScreen", content.getId()+"");
        byte[] byteArray=null;
        Bitmap screenshot=null;
        try {
            if (content != null) {
                int width = content.getWidth();
                int height = content.getHeight();

                screenshot = Bitmap.createBitmap(width, height,
                        Bitmap.Config.RGB_565);
                content.draw(new Canvas(screenshot));
                Log.d("captureScreen", "success");
            }
        } catch (Exception e) {
            Log.d("captureScreen", "Failed");
        }

        try{


            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            screenshot.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byteArray = stream.toByteArray();
            Log.d("byte array", "sucesss");
            } catch(Exception e){
                Log.d("byte array", "failed");
            }




        Request.Callback callback = new Request.Callback() {

            public void onCompleted(Response response) {


                JSONObject graphResponse = response.getGraphObject()
                .getInnerJSONObject();
                Log.d("onCompleted", "2 sucess");
                String postId = null;
                try {
                    postId = graphResponse.getString("id");
                    Log.d("onCompleted", "3 sucess");
                } catch (JSONException e) {
                    Log.d("json failed", "failed");
                    Log.i(TAG, "JSON error " + e.getMessage());
                }

                FacebookRequestError error = response.getError();
                if (error != null) {

                } else {

                    CreateDialog("your post was a sucess", "posted");
                }
            }

        };



      Bundle params = new Bundle();
      params.putString("message","tester"); 
    //params.putString("method", "photos.upload");
    //params.putByteArray("source", byteArray); 
    // params.putString("caption", "test Caption");

        Request request = new Request(session, "me/photos", params,
                HttpMethod.POST, callback);

        RequestAsyncTask task = new RequestAsyncTask(request);
        task.execute();
4

1 に答える 1

0

私のアプリケーションでは、次のコードを使用して Facebook で写真とテキストを共有しました。

ByteArrayOutputStream baos = new ByteArrayOutputStream();
yourbitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
params.putString("caption",
    "This is screen shot from MyApp. Visit my application blah blah blah");
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST",
    new SampleUploadListener(), null);
于 2013-06-03T07:23:32.393 に答える