21.04.2014 Views

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CURSO ANDROID<br />

112<br />

El segundo listener, una vez ya ha ocurrido la autenticación, borrará las cre<strong>de</strong>nciales guardadas en los<br />

SharedPreferences.<br />

twitter_auth = new OnClickListener() {<br />

@Overri<strong>de</strong><br />

public void onClick(View v) {<br />

txtTwStatus.setText(“Twitter status: iniciando sesión”);<br />

try {<br />

String authUrl = provi<strong>de</strong>r.retrieveRequestToken(consumer,<br />

“mdw://twitter”);<br />

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));<br />

} catch (OAuthMessageSignerException e) {<br />

e.printStackTrace();<br />

} catch (OAuthNotAuthorizedException e) {<br />

e.printStackTrace();<br />

} catch (OAuthExpectationFailedException e) {<br />

e.printStackTrace();<br />

} catch (OAuthCommunicationException e) {<br />

e.printStackTrace();<br />

}<br />

}<br />

};<br />

Es importante notar que las cre<strong>de</strong>nciales recibidas <strong>de</strong> Twitter (key y secret) no expiran y son válidas<br />

mientras el usuario no revoque los permisos <strong>de</strong> la aplicación, lo que hacemos al <strong>de</strong>sautorizar es borrar<br />

las cre<strong>de</strong>nciales guardadas por lo que la siguiente vez que presionemos el botón solicitaremos nuevas.<br />

Para terminar el método onCreate revisamos el valor <strong>de</strong> twitter_active y actualizamos el texto <strong>de</strong>l botón<br />

y <strong>de</strong>l TextView <strong>de</strong> estatus.<br />

if (twitter_active) {<br />

txtTwStatus.setText(“Twitter status: sesión iniciada “);<br />

btnTwLogin.setText(“Deautorizar twitter”);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!