Recibí "solicitud fallida" al intentar publicar en el muro de Facebook

Estoy usando la conexión de Facebook con SSO para iniciar/registrar usuarios en mi aplicación y quiero pedirle al usuario que publique en el muro después de cada inicio de sesión.

Pero, en el onComplete de requestListener (se mostró el cuadro de diálogo Publicar en el muro y el usuario tocó Compartir), recibo una respuesta falsa. No descubrí lo que significa en los documentos de FB SDK, pero se publicó algo en mi muro. Se suponía que la respuesta devolvería una cadena con formato JSON, por lo que cuando intento ejecutar "mensaje = json.getString("mensaje");, aparece un error de Facebook que simplemente imprime "solicitud fallida"...

gato de registro:

07-27 12:58:09.170: W/FacebookConnect(26086): Activity Started
07-27 12:58:12.300: W/FacebookConnect(26086): User authorized
07-27 12:58:12.300: E/FacebookConnect(26086): onComplete called at facebook.authorize
07-27 12:58:12.300: E/FacebookConnect(26086): Access Token: AAAC1sJLmgzkBAD0M40SQLgluPU...
07-27 12:58:12.860: D/webviewglue(26086): nativeDestroy view: 0x223888
07-27 12:58:13.420: I/SqliteDatabaseCpp(26086): sqlite returned: error code = 14, msg = cannot open file at line 27701 of [8609a15dfa], db=/data/data/androidhive.dashboard/databases/webview.db
07-27 12:58:13.420: I/SqliteDatabaseCpp(26086): sqlite returned: error code = 14, msg = os_unix.c: open() at line 27701 - "" errno=2 path=/CachedGeoposition.db, db=/data/data/androidhive.dashboard/databases/webview.db
07-27 12:58:14.670: D/SampleRequestListener(26086): Response: {"id":"1123123","name"...
07-27 12:58:14.680: E/FacebookConnect(26086): JSON {"work":[{"position"...
07-27 12:58:17.150: E/SampleDialogListener(26086): Dialog Success! post_id=1003157...
07-27 12:58:17.720: E/WallPostRequestListener(26086): Got response: false
07-27 12:58:17.720: E/WallPostRequestListener(26086): Facebook Error: request failed

Mi código (se produce un error en la clase WallPostRequestListener):

public class FacebookConnectActivity extends Activity {
private static final String TAG_JSON = "json";
static Facebook facebook = new Facebook("11111111111111");
AsyncFacebookRunner mAsyncRunner;
private SharedPreferences mPrefs;
JSONObject json;
Context ctx = this;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.resgatar_produto_layout);
    Log.w("FacebookConnect", "Activity Started");

    mPrefs = getPreferences(MODE_PRIVATE);
    String access_token = mPrefs.getString("access_token", null);
    long expires = mPrefs.getLong("access_expires", 0);
    if(access_token != null) {
        facebook.setAccessToken(access_token);

    }
    if(expires != 0) {
        facebook.setAccessExpires(expires);
    }

    if(!facebook.isSessionValid()) {

    facebook.authorize(this, new String[] {"email", "user_photos", "user_birthday", "user_hometown", "user_relationships","user_location", "user_work_history", "publish_actions"}, new DialogListener() {
        @Override
        public void onComplete(Bundle values) {
            Log.w("FacebookConnect", "User authorized");
            Log.e("FacebookConnect", "onComplete called at facebook.authorize");
            Log.e("FacebookConnect", "Access Token: "+facebook.getAccessToken().toString());
            mAsyncRunner = new AsyncFacebookRunner(facebook);
            mAsyncRunner.request("me", new SampleRequestListener());
            Bundle params = new Bundle();
            params.putString("link", "www.qranio.com");
            facebook.dialog(ctx, "feed", params, new SampleDialogListener());
        }

        @Override
        public void onFacebookError(FacebookError error) {
            Log.w("FacebookConnect", "Error authorizing: "+error.toString());
        }

        @Override
        public void onError(DialogError e) {}

        @Override
        public void onCancel() {}   
    });

    }

}

public static  void logoutFB(){
    if(facebook.isSessionValid()){
        facebook.setAccessToken(null);
    }
}

public void startDataProcess(){

    Intent a = new Intent(FacebookConnectActivity.this, FacebookDataProcess.class);
    a.putExtra(TAG_JSON, json.toString());
    startActivity(a);
    finish();
}





public class SampleDialogListener extends BaseDialogListener {

    public void onComplete(Bundle values) {
        final String postId = values.getString("post_id");
        if (postId != null) {
            Log.e("SampleDialogListener", "Dialog Success! post_id=" + postId);
            mAsyncRunner.request(postId, new WallPostRequestListener());
        } else {
            Log.e("SampleDialogListener", "No wall post made"); //Usuario clicou em Cancelar
            startDataProcess();
        }
    }

    public void onCancel(){ //Usuario clicou no X do dialog
        Log.w("FacebookConnect", "Post to Wall Canceled");
        startDataProcess();
    }
}

public class WallPostRequestListener extends BaseRequestListener {

    public void onComplete(final String response, final Object state) {

        Log.e("WallPostRequestListener", "Got response: " + response);
        String message = "<empty>";
        try {
            JSONObject json = Util.parseJson(response);
            message = json.getString("message");
        } catch (JSONException e) {
            Log.e("WallPostRequestListener", "JSON Error in response");
        } catch (FacebookError e) {
            Log.e("WallPostRequestListener", "Facebook Error: " + e.getMessage());
            //Toast.makeText(ctx, "Erro ao postar no Facebook.", Toast.LENGTH_LONG).show();
        }
        //startDataProcess();
    }
}


public class SampleRequestListener extends BaseRequestListener {

    public void onComplete(final String response, final Object state) {
        try {

            // process the response here: executed in background thread
            Log.d("SampleRequestListener", "Response: " + response.toString());
            json = Util.parseJson(response);
            Log.e("FacebookConnect", "JSON " + json.toString());

            //startDataProcess();

            // then post the processed result back to the UI thread
            // if we do not do this, an runtime exception will be generated
            // e.g. "CalledFromWrongThreadException: Only the original
            // thread that created a view hierarchy can touch its views."

        } catch (JSONException e) {
            Log.w("Facebook-Example", "JSON Error in response");
        } catch (FacebookError e) {
            Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
        }

    }
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    facebook.authorizeCallback(requestCode, resultCode, data);
    try{
        mAsyncRunner = new AsyncFacebookRunner(facebook);
        mAsyncRunner.request("me", new SampleRequestListener());
        Bundle params = new Bundle();
        params.putString("link", "www.qranio.com");
        //params.putString("display", "touch");
        facebook.dialog(ctx, "feed", params, new SampleDialogListener());
        Log.e("FacebookConnect", "Authentication authorizeCallback called (onActivityResult)");
        Log.e("FacebookConnect", "Access Token: "+facebook.getAccessToken().toString());
        //facebook.
        //if (facebook.isSessionValid()){

        //}else{
            //Log.e("FacebookConnect", "Invalid facebook session while trying to fetch user data");
        //}*/

    }catch(FacebookError fbe){
        Log.e("FacebookConnect", "onActivityResult FacebookError " + fbe.toString());
    }catch (Exception e){
        Log.e("FacebookConnect", "onActivityResult Exception " + e.toString());
    }

}

}

preguntado el 27 de julio de 12 a las 17:07

¿WallPostRequestListener es inútil? Acabo de eliminarlo de SampleDialogListener.onComplete y funcionó bien... -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.