0
當我在我的設備上使用eclipse測試這個應用程序時一切都好;但是當我發佈這個應用程序在谷歌Play商店的Facebook登錄失敗! 爲什麼? 請幫助我! 它是一個簡單的應用程序(市場上的「咖啡休息時間」);與市場上的facebook登錄的android錯誤
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;
}
}
我不明白爲什麼我這個問題
你添加應用程序的發佈的散列鍵在Facebook上籤署您的開發者帳戶的密鑰?如果你還沒有,你需要把它和你的debug.keystore Key Hash一起加入。如果你添加了它,那就錯了,需要重新創建。 –
您是否添加了簽名的keyhash值FB ...? – Basil
如何獲得fb @Basil簽名的keyhash – alicanbatur