I am trying to integrate Facebook login with my android application but whenever I try to login i get this "FacebookError Exception". Can anyone plz tell me what's causing it and how to handle it? I am using Facebook sdk version 3.23.1.
Here is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//connect=(Button)findViewById(R.id.authButton);
button=(ImageView)findViewById(R.id.connect);
button.setOnClickListener(this);
updateButtonImage();
}
private void updateButtonImage() {
if(fb.isSessionValid())
{
button.setImageResource(R.drawable.logout);
}
else
{
button.setImageResource(R.drawable.login);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
if(fb.isSessionValid())
{
//button close our session, log out of facebook
try {
fb.logout(getApplicationContext());
updateButtonImage();
} catch (IOException e) {
e.printStackTrace();
}
}
else
{
//login to facebook
fb.authorize(MainActivity.this, new Facebook.DialogListener() {
@Override
public void onComplete(Bundle values) {
updateButtonImage();
}
@Override
public void onFacebookError(FacebookError e) {
Toast.makeText(MainActivity.this, "FbError", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(DialogError e) {
Toast.makeText(MainActivity.this, "OnError", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(MainActivity.this, "OnCancel", Toast.LENGTH_SHORT).show();
}
});
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
fb.authorizeCallback(requestCode, resultCode, data);
}
}
Aucun commentaire:
Enregistrer un commentaire