Java 类com.facebook.RequestAsyncTask 实例源码

项目:vocefiscal-android    文件:FiscalizacaoConcluidaActivity.java   
private void publishStory(Session session) 
{
    Bundle postParams = new Bundle();
    postParams.putString("name", "Você Fiscal");

    // Receber os dados da eleição!!!
    postParams.putString("message", "Eu fiscalizei a seção: "+ this.secao +"\nNa zona eleitoral: " + this.zonaEleitoral + "\nNo município de: " + this.municipio);          
    postParams.putString("description", "Obrigado por contribuir com a democracia!");
    postParams.putString("link", "http://www.vocefiscal.org/");
    postParams.putString("picture", "http://imagizer.imageshack.us/v2/150x100q90/913/bAwPgx.png");

    Request.Callback callback= new Request.Callback() 
    {
        public void onCompleted(Response response) 
        {
            JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
            String postId = "Compartilhado com sucesso!";
            try 
            {
                postId = graphResponse.getString("Compartilhado com sucesso!");
            } catch (JSONException e) 
            {
            }
            FacebookRequestError error = response.getError();
            if (error != null) 
            {
                Toast.makeText(FiscalizacaoConcluidaActivity.this.getApplicationContext(),error.getErrorMessage(),Toast.LENGTH_SHORT).show();
            } else 
            {
                Toast.makeText(FiscalizacaoConcluidaActivity.this.getApplicationContext(),  postId, Toast.LENGTH_LONG).show();
            }
        }
    };

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

    RequestAsyncTask task = new RequestAsyncTask(request);
    task.execute();
}
项目:FacebookImageShareIntent    文件:FacebookShareActivity.java   
private void postImageToFacebook() {
    Session session = Session.getActiveSession();
    final Uri uri = (Uri) mExtras.get(Intent.EXTRA_STREAM);
    final String extraText = mPostTextView.getText().toString();
    if (session.isPermissionGranted("publish_actions"))
    {
        Bundle param = new Bundle();

        // Add the image
        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            byte[] byteArrayData = stream.toByteArray();
            param.putByteArray("picture", byteArrayData);
        } catch (IOException ioe) {
            // The image that was send through is now not there?
            Assert.assertTrue(false);
        }

        // Add the caption
        param.putString("message", extraText);
        Request request = new Request(session,"me/photos", param, HttpMethod.POST, new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
                addNotification(getString(R.string.photo_post), response.getGraphObject(), response.getError());

            }
        }, null);
        RequestAsyncTask asyncTask = new RequestAsyncTask(request);
        asyncTask.execute();
        finish();
    }
}
项目:CodePix-Android    文件:ImageDistortedUploadActivity.java   
private void publishStory() {

    try {
    Session.openActiveSession(this, true, new Session.StatusCallback() {

      // callback when session changes state
         @Override
          public void call(Session session, SessionState state, Exception exception) {
              if (session.isOpened()) {



                    if (session != null){


                    if(session.isOpened() && state == SessionState.OPENED && !session.getPermissions().contains("publish_stream")){
                          final String[] PERMISSION_ARRAY_PUBLISH = {"publish_stream"};
                          final List<String> permissionList = Arrays.asList(PERMISSION_ARRAY_PUBLISH);
                          session.requestNewPublishPermissions(new NewPermissionsRequest(ImageDistortedUploadActivity.this,permissionList ));
                          return;
                      }

                   // Bundle postParams = new Bundle();
                   // postParams.putString("name", "Facebook SDK for Android");
                   // postParams.putString("caption", "Build great social apps and get more installs.");
                   // postParams.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
                   // postParams.putString("link", "https://developers.facebook.com/android");
                   // postParams.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
                    byte[] data = null;

                    Bitmap bi = BitmapFactory.decodeFile(new File(filePathDistorted).getAbsolutePath());
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                    data = baos.toByteArray();




                    Request.Callback callback= new Request.Callback() {
                        @Override
                        public void onCompleted(Response response) {
                            System.out.println("response"+response);
                        }
                    };

                    Request request = Request.newUploadPhotoRequest(session,bi, callback);
                 Bundle params = request.getParameters();
                  params.putString("message", editTextCaption.getText().toString()+": To view image, click here to download CodePix");
                   // params.putString("method", "photos.upload");
                    //params.putByteArray("picture", data);
                    //params.putString("link", "https://developers.facebook.com/android");
                request.setParameters(params);
                    RequestAsyncTask task = new RequestAsyncTask(request);
                    task.execute();
                }
                    //Request.executeBatchAsync(request); 
              }    
          }

    });
} catch (Exception e) {
    // TODO Auto-generated catch block
    pd.dismiss();
    e.printStackTrace();
    GlobalMethods.showMessage(getApplicationContext(), getString(R.string.internet_error));
}




    }
项目:cursoAndroidUTN    文件:lay_facebook.java   
private void publishStory()
{
    Session session = Session.getActiveSession();
    pendingPublishReauthorization = false;
    if (session != null)
    {

        // Check for publish permissions
        List<String> permissions = session.getPermissions();
        if (!isSubsetOf(PERMISSIONS, permissions))
        {
            pendingPublishReauthorization = true;
            Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
            session.requestNewPublishPermissions(newPermissionsRequest);
            return;
        }

        Bundle postParams = new Bundle();
        postParams.putString("name", "Facebook SDK for Android");
        postParams.putString("caption", "Build great social apps and get more installs.");
        postParams.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
        postParams.putString("link", "https://developers.facebook.com/android");
        postParams.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

        Request.Callback callback = new Request.Callback()
        {
            public void onCompleted(Response response)
            {
                JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
                String postId = null;
                try
                {
                    postId = graphResponse.getString("id");
                }
                catch (JSONException e)
                {
                    Log.i("KeyHash:", "JSON error " + e.getMessage());
                }
                FacebookRequestError error = response.getError();
                if (error != null)
                {
                    Toast.makeText(getApplicationContext(), postId, Toast.LENGTH_SHORT).show();
                }
                else
                {
                    Toast.makeText(getApplicationContext(), error.getErrorMessage(), Toast.LENGTH_LONG).show();
                }
            }
        };

        Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);
        RequestAsyncTask task = new RequestAsyncTask(request);
        task.execute();
    }

}