如何在未经批准的情况下将照片发布到Facebook

时间:2014-05-14 19:10:44

标签: android facebook

我想将我的位图照片发布到我应用的相册,而不是从Facebook批准。据我所知,当登录成功时,它会有一个loginButton,一个共享按钮出现,点击共享按钮时上传位图照片。一切都很顺利,但我不得不批准相册中的照片与朋友分享。这是我的代码,由facebook的开发者网站描述片段

public class MainFragment extends Fragment implements OnClickListener {
    private static final String TAG = "MainFragment";
    private UiLifecycleHelper uiHelper;
    LoginButton authButton;
    Button bShare;

    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            onSessionStateChange(session, state, exception);
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.main, container, false);
        authButton = (LoginButton) view.findViewById(R.id.authButton);

        authButton.setFragment(this);

        bShare = (Button) view.findViewById(R.id.bShare);
        bShare.setOnClickListener(this);

        return view;
    }

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

        uiHelper = new UiLifecycleHelper(getActivity(), callback);
        uiHelper.onCreate(savedInstanceState);
    }

    @Override
    public void onResume() {
        super.onResume();
        // For scenarios where the main activity is launched and user
        // session is not null, the session state change notification
        // may not be triggered. Trigger it if it's open/closed.
        Session session = Session.getActiveSession();
        if (session != null && (session.isOpened() || session.isClosed())) {
            onSessionStateChange(session, session.getState(), null);
        }

        uiHelper.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        uiHelper.onSaveInstanceState(outState);
    }

    private void onSessionStateChange(Session session, SessionState state,
            Exception exception) {
        if (state.isOpened()) {
            Log.i(TAG, "Logged in...");

            bShare.setVisibility(View.VISIBLE);

        } else if (state.isClosed()) {
            Log.i(TAG, "Logged out...");
            bShare.setVisibility(View.INVISIBLE);

        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        uiHelper.onActivityResult(requestCode, resultCode, data);

        uiHelper.onActivityResult(requestCode, resultCode, data,
                new FacebookDialog.Callback() {
                    @Override
                    public void onError(FacebookDialog.PendingCall pendingCall,
                            Exception error, Bundle data) {
                        Log.e("Activity",
                                String.format("Error: %s", error.toString()));
                    }

                    @Override
                    public void onComplete(
                            FacebookDialog.PendingCall pendingCall, Bundle data) {
                        Log.i("Activity", "Success!");

                    }
                });

    }

    @Override
    public void onClick(View v) {

        Bitmap image = Joursey.img;

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

            @Override
            public void onCompleted(Response response) {
                if (response.getError() != null) {
                    Log.d("Upload",
                            "photo upload problem. Error="
                                    + response.getError());

                    Toast.makeText(getActivity(),
                            "Problem occured while uploading",
                            Toast.LENGTH_LONG).show();

                }

                Object graphResponse = response.getGraphObject().getProperty(
                        "id");
                if (graphResponse == null || !(graphResponse instanceof String)
                        || TextUtils.isEmpty((String) graphResponse)) {
                    Log.d("Upload", "failed photo upload/no response");

                    Toast.makeText(getActivity(),
                            "Failed to upload/no response", Toast.LENGTH_LONG)
                            .show();
                } else {
                    Log.d("Upload", "Successfully Uploaded");
                    Toast.makeText(getActivity(), "Successfully Uploaded",
                            Toast.LENGTH_LONG).show();
                }

            }
        };

        Request request = Request.newUploadPhotoRequest(
                Session.getActiveSession(), image, UploadCallback);

        Bundle params = request.getParameters();
        params.putString("name", "This is my favorite jursey");
        request.setParameters(params);
        request.executeAsync();

    }
}

我想这样我不需要从我的个人资料中删除它,它应该是自动发布的吗?我需要在这里做些什么改变?

0 个答案:

没有答案