문제

안녕하세요 여러분 저는 사용자를 Facebook 계정에 로그인하고 프로필에 콘텐츠를 게시 할 수 있습니다. 그러나 내가 할 수없는 것은 Facebook 사용자 정보를 얻는 것입니다. 나는 페이스 북이 세션을 위해주는 액세스 토큰이 어디에 있는지 모른다. 나는 fbconnect.jar를 사용하고 있으며 lib 폴더에 추가하고 다음 경로를 빌드 경로 다음과 같습니다.

private Facebook facebookClient;
String information;
Button fb;
//** Called when the activity is first created. *//*
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    fb = (Button)findViewById(R.id.fb);
    fb.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
        whenFbPressed();

        }
    });



}


@Override
public void onCancel() {
    // TODO Auto-generated method stub

}

@Override
public void onComplete(Bundle values) {
    // TODO Auto-generated method stub

    if (values.isEmpty()) {
        return;
    }

    if (!values.containsKey("post_id")) {
        try {
            Bundle parameters = new Bundle();
            parameters
                    .putString("message", "is Listening to  " );// the

              parameters.putString("attachment",
              "{\"name\":\"My Test Image\"," + "\"href\":\"" +
              "http://www.google.com" + "\"," +
              "\"media\":[{\"type\":\"image\",\"src\":\"" +
              "http://www.google.com/logos/mucha10-hp.jpg" +
              "\",\"href\":\"" + "http://www.google.com" + "\"}]" + "}");

            parameters.putString("attachment", "{\"name\":\"" + "Abhishek"
                    + "\"," + "\"href\":\"" + "www.google.com" + "\"}]" + "}");

            facebookClient.dialog(this, "stream.publish", parameters, this);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

}

@Override
public void onError(DialogError e) {
    // TODO Auto-generated method stub
    System.out.println("Error: " + e.getMessage());
}

@Override
public void onFacebookError(FacebookError e) {
    // TODO Auto-generated method stub
    System.out.println("Error: " + e.getMessage());

}

public void onClick(View v) {
    if (v == fb) {
        facebookClient = new Facebook("App_ID");
        // facebookClient = new Facebook("App_ID");
        // replace APP_API_ID with your own
        facebookClient.authorize(this, new String[] { "publish_stream",
                "read_stream", "offline_access" }, this);
    }
}

public void whenFbPressed(){
    facebookClient = new Facebook("App_ID");
    // facebookClient = new Facebook("App_ID");
    // replace APP_API_ID with your own
    facebookClient.authorize(this, new String[] { "publish_stream",
            "read_stream", "offline_access","email" }, this);

}
도움이 되었습니까?

해결책

/* this is user defined method  to fetch current user firstnam and last name */

public void getUser(){

    try{
        JSONObject json = Util.parseJson( mFacebook.request("me"));
        String facebookID = json.getString("id");
        String firstName = json.getString("first_name");
        String lastName = json.getString("last_name");
        mFirstName=firstName;
        mLastName=lastName;
        mText.setText("You are logged in : "+mFirstName+"."+mLastName);
        System.out.println("Firstname>>"+firstName+" LastName>>"+lastName);
    }catch (Exception e) {
        // TODO: handle exception
    }catch(FacebookError fbe){

    }
}

다른 팁

글쎄, 나는 그것을 얻었다.

Facebook은 사용자가 응용 프로그램을 등록하고 주어진 권한을 허용 할 때 액세스 토큰을 보냅니다.

그래서 내 onComplete() 방법이 코드의 피시를 추가했습니다.

if (values.isEmpty()) {
     return;
}
if (!values.containsKey("post_id")) {
     try {
          Log.d("++++++++++++", facebookClient.getAccessToken());
          Log.d("++++++++++++", facebookClient.request("me"));
     }
}

그리고 내 로그에서 그것은 나에게 데이터를 제공합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top