以编程方式从Android应用程序登录到Facebook

时间:2014-10-16 07:01:44

标签: android facebook checkin

如何使用像foresquare这样的Android应用程序以编程方式检入?问题描述得很好 我不确定facebook API是否支持

1 个答案:

答案 0 :(得分:1)

尝试使用以下方法:

private ArrayList<String> permissions = new ArrayList<String>();

    permissions.addAll(Arrays.asList("photo_upload","publish_checkins","publish_actions"));

    Session session = openActiveSession(YOUR ACTIVITY NAME.this, true, new Session.StatusCallback() {
            @SuppressLint("UseValueOf")
            @Override
            public void call(Session session, SessionState state, Exception exception) {
                if (session.isOpened()) {

                    try {

                        if (getCurrentLocation() != null) {
                            location.put("latitude", new Double(YOUR LATITUDE));
                            location.put("longitude", new Double(YOUR LONGITUDE));
                        } else {
                            Toast.makeText(YOUR ACTIVITY NAME.this, getString(R.string.facebook_location_not_found), Toast.LENGTH_LONG).show();
                            return;
                        }

                    } catch (Exception e) {

                        e.printStackTrace();
                    }
                    Bundle params = new Bundle();
                    params.putString("place", id); 
                    params.putString("coordinates", location.toString());

                    if (edtMessage.getText().toString().trim().length() > 0) {
                        params.putString("message", message);
                    }
                    Request.Callback callback = new Request.Callback() {

                        @Override
                        public void onCompleted(Response response) {
                            Toast.makeText(YOUR ACTIVITY.this,"Checkins success, Toast.LENGTH_LONG).show();
                        }
                    };
                    Request request = new Request(session, "me/checkins", params, HttpMethod.POST, callback);

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

        }, permissions);