当我用 eclipse 在我的设备上测试这个应用程序时一切正常;但是当我在 google play store 上发布这个应用程序时,facebook 登录失败!为什么?请帮帮我!!它是一个简单的应用程序(市场上的“咖啡休息时间”);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main );
elementoInserito=(EditText)findViewById(R.id.editTextElementoInserito);
elementoEstratto=(TextView)findViewById(R.id.textViewElementoEstratto);
inserisci=(Button)findViewById(R.id.buttonInserisci);
stampa=(Button)findViewById(R.id.buttonStampa);
facebookLogin=(Button)findViewById(R.id.facebookLogin);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session =Session.restoreSession(this,null,statusCallback,savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(newSession.OpenRequest(this).setCallback(statusCallback));
}
}
inserisci.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
inizializza_array(elementoInserito);
elementoInserito.setText("");
}
});
updateView();
}
private void updateView() {
Session session = Session.getActiveSession();
if (session.isOpened()) {
facebookLogin.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
onClickLogout(); }
});
}
else {
facebookLogin.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
onClickLogin(); }
});
}
}
private void onClickLogin() {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
} else {
Session.openActiveSession(this, true, statusCallback);
}
Bundle bundle=new Bundle();
Session.saveSession(session,bundle);
Toast.makeText(getApplicationContext(),
"sto salvando la sessione "+session.getState(),
Toast.LENGTH_LONG).show();
}
private void onClickLogout() {
Session session = Session.getActiveSession();
if (!session.isClosed()) {
session.closeAndClearTokenInformation();
}
}
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
updateView();
}
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
public void inizializza_array(EditText n){
this.ins=""+n.getText();
if(ins==""){
Toast.makeText(getApplicationContext(),
"errore: campo vuoto",
Toast.LENGTH_LONG).show();
}
else{
lista.add(ins);
}
}
public void stampa(View v){
if(lista.size()==0){
elementoEstratto.setText("Inserire elementi");
}
else{
Random random = new Random();
String x = lista.get(random.nextInt(lista.size()));
elementoEstratto.setText(x);
lista.clear();
try {
publishStory(x);
} catch (Exception e) {
}
}
}
public void onStart() {
super.onStart();
Session.getActiveSession().addCallback(statusCallback);
}
@Override
public void onStop() {
super.onStop();
Session.getActiveSession().removeCallback(statusCallback);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Session session = Session.getActiveSession();
Session.saveSession(session, outState);
}
public void publishStory(String sorteggiato) {
Session session = Session.getActiveSession();
try {
if (session != null){
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle postParams = new Bundle();
postParams.putString("name",""));
postParams.putString("caption","");
postParams.putString("description","");
Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
} catch (JSONException e) {
Log.i(TAG,
"JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(getApplicationContext(),
error.getErrorMessage(),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
"shared",//postId
Toast.LENGTH_LONG).show();
}
}
};
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
else{
Toast.makeText(getApplicationContext(),
"effettua il Login su Facebook per condividere con i tuo amici",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
// TODO: handle exception
}
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
for (String string : subset) {
if (!superset.contains(string)) {
return false;
}
}
return true;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Intent intent = new Intent (MainActivity.this,Info.class);
//Intent intent2 = new Intent(MainActivity.this,Caffe.class);
menu.add("About Coffee Break").setIntent(intent);
//menu.add("Il caffè").setIcon(R.drawable.caffe).setIntent(intent2);
return true;
}
}
我不明白为什么我有这个问题