简体   繁体   English

将照片发布到Facebook权限Android SDK

[英]Publish photo to Facebook permissions Android SDK

i am trying to publish a photo to facebook for android SDK i do not want to keep the user logged in all i want when user click of share it ask for login (if not logged in) and publish a photo to facebook wall 我正在尝试将照片发布到android SDK的Facebook中,我不想让用户保持登录状态。当用户单击共享时,它要求登录(如果未登录),然后将照片发布到Facebook墙

here is the code i write but it gives an error 这是我写的代码,但它给出了一个错误

an attempt was made to request new permissions for a session that has pending request

Code: 码:

Session session = new Session(this);
    Session.setActiveSession(session);

    session.openForPublish(new Session.OpenRequest(this)
    .setCallback(null).setPermissions(permissions));

    Session.NewPermissionsRequest newPermissionsRequest = 
            new Session.NewPermissionsRequest(this, Arrays.asList("publish_actions"))
    .setRequestCode(100);

    Session.openActiveSession(this, true, null)
        .requestNewPublishPermissions(newPermissionsRequest);




    Drawable d = getResources().getDrawable(R.drawable.s0);

    Bitmap bmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Config.ARGB_8888);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    bmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);

    byte[] byteArray = stream.toByteArray();

    Bundle params = new Bundle();

    params.putByteArray("picture", byteArray);
    params.putString("message", "");

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

    request.setCallback(new Request.Callback() {

        @Override
        public void onCompleted(Response response) {
            if (response.getError()==null) {
                Toast.makeText(getApplicationContext(), "Successfully posted photo", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), response.getError().getErrorMessage(), Toast.LENGTH_SHORT).show();
            }

        }
    });
    request.executeAsync();

YOu can use Facebook SDK for anything related to facebook.. SDK is available at facebook site.. 您可以将Facebook SDK用于与Facebook相关的任何事情。SDK可从facebook网站上获得。

Facebook SDk for Android 适用于Android的Facebook SDk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM