안녕 모두 내 안드로이드 응용 프로그램에서 야후 메일 서비스를 통합하고 싶습니다. Google에 대한 많은 검색 후 그 사람을 위해 나에게 도움이되는 어떤 링크 나 제안을 내게 제공 해주지 않기 위해 적절한 튜토리얼을 얻지 못했습니다.내 Android 애플리케이션에 yahoo 메일 서비스를 통합하는 방법은 무엇입니까?
0
A
답변
3
위의 soure 코드를 참조하십시오.
import oauth.signpost.OAuth;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthProvider;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;
import oauth.signpost.signature.HmacSha1MessageSigner;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.synapse.selfervices.R;
public class YahooScreen extends Activity {
private static final String REQUEST_TOKEN_ENDPOINT_URL ="https://api.login.yahoo.com/oauth/v2/get_request_token";
private static final String ACCESS_TOKEN_ENDPOINT_URL ="https://api.login.yahoo.com/oauth/v2/get_access_token";
private static final String AUTHORIZE_WEBSITE_URL ="https://api.login.yahoo.com/oauth/v2/request_auth";
private static final int PIN_DIALOG = 0;
String CALLBACK_URL = OAuth.OUT_OF_BAND; // this should be the same as the
// SCHEME and HOST values in
// your AndroidManifest.xml file
String CONSUMER_KEY = "";//
String CONSUMER_SECRET = "";
private CommonsHttpOAuthConsumer myConsumer;
private CommonsHttpOAuthProvider myProvider;
private String requestToken;
private String accessToken;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
callOAuth();
showDialog(PIN_DIALOG);
// createPinDialog().show();
}
private void callOAuth() {
try {
// retrieve the consumer token and then sign it
myConsumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY,
CONSUMER_SECRET);
myConsumer.setMessageSigner(new HmacSha1MessageSigner());
HttpClient client = new DefaultHttpClient();
// retrieve the provider by using the signed consumer token
myProvider = new CommonsHttpOAuthProvider(
REQUEST_TOKEN_ENDPOINT_URL, ACCESS_TOKEN_ENDPOINT_URL,
AUTHORIZE_WEBSITE_URL, client);
myProvider.setOAuth10a(true);
String aUrl = myProvider.retrieveRequestToken(myConsumer,
CALLBACK_URL);
requestToken = myConsumer.getToken();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(aUrl)));
} catch (Exception ex) {
Toast.makeText(getApplicationContext(), ex.getMessage(),
Toast.LENGTH_LONG).show();
Log.e(ex.getMessage(), ex.toString());
}
}
// this is the callback function that will run when oauth authenticates
// successfully
@Override
protected void onNewIntent(Intent intent) {
System.out.println("OnNewIntent...");
Toast.makeText(getApplicationContext(), "OnNewIntent - It works!",
Toast.LENGTH_LONG).show();
// whatever you want to do after authenticating goes here ....
}
AlertDialog createPinDialog() {
LayoutInflater factory = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
// LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.pin, null);
final EditText pinText = (EditText) textEntryView
.findViewById(R.id.pin_text);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Twitter OAuth PIN");
builder.setView(textEntryView);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (pinText != null)
gotOAuthPin(pinText.getText().toString());
onResume();
}
});
return builder.create();
}
private void gotOAuthPin(String pin) {
SharedPreferences.Editor editor = getSharedPreferences("yahoo",
MODE_PRIVATE).edit();
try {
myProvider.retrieveAccessToken(myConsumer, pin);
accessToken = myConsumer.getToken();
} catch (OAuthMessageSignerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OAuthCommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (accessToken != null && accessToken.length() > 0) {
Toast.makeText(this, "Authorized", Toast.LENGTH_SHORT).show();
HttpPost request = new HttpPost(
"http://social.yahooapis.com/v1/user/profile?format=json");
StringEntity body = null;
/*
* try { body = new StringEntity("city=hamburg&label=" +
* URLEncoder.encode("Send via Signpost!", "UTF-8")); } catch
* (UnsupportedEncodingException e1) { // TODO Auto-generated catch
* block e1.printStackTrace(); }
* body.setContentType("application/x-www-form-urlencoded");
* request.setEntity(body);
*/
try {
myConsumer.sign(request);
} catch (OAuthMessageSignerException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (OAuthMessageSignerException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (OAuthExpectationFailedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (OAuthCommunicationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("Sending update request to Fire Eagle...");
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = null;
try {
response = httpClient.execute(request);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText(
this,
"Response: " + response.getStatusLine().getStatusCode()
+ " " + response.getStatusLine().getReasonPhrase(),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Not Authorized", Toast.LENGTH_SHORT).show();
}
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case PIN_DIALOG:
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.pin, null);
final EditText pinText = (EditText) textEntryView
.findViewById(R.id.pin_text);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("OAuth PIN");
builder.setView(textEntryView);
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
if (pinText != null)
gotOAuthPin(pinText.getText().toString());
}
});
return builder.create();
}
return super.onCreateDialog(id);
}}
+0
Oauth Library를 다운로드 할 수있는 곳에서 야후 메일 서비스를 열고 싶습니다. pls에서 나에게 ... 안드로이드에 대한 야후 통합의 데모를 알려줄 수 있습니까? –
+0
http://code.google.com/p/oauth-signpost/downloads/list –
+0
안녕하세요, 귀하의 회신을 보내 주셔서 감사합니다 안드로이드에 대한 야후 로그인의 전체 예제를 가지고 ... –
관련 문제
- 1. Android 애플리케이션에 Google 리더를 통합하는 방법은 무엇입니까?
- 2. Linkedin을 Android 애플리케이션에 통합하는 방법은 무엇입니까?
- 3. Android 애플리케이션에 iContact를 통합하는 방법은 무엇입니까?
- 4. 페이팔을 애플리케이션에 통합하는 방법은 무엇입니까?
- 5. 자동화 된 모니터링/서비스를 gwt 애플리케이션에 통합하는 방법은 무엇입니까?
- 6. Core Data를 기존 애플리케이션에 통합하는 방법은 무엇입니까?
- 7. 안드로이드에서 내 애플리케이션에 안드로이드 맵 애플리케이션을 통합하는 방법은 무엇입니까?
- 8. 문서 스캐닝을 Qt 애플리케이션에 통합하는 방법은 무엇입니까?
- 9. 내 Android 앱을 SL4A와 통합하는 방법은 무엇입니까?
- 10. 내 애플리케이션에 yahoo 로그인을 통합하려면 어떻게해야합니까?
- 11. Android 통합 Yahoo
- 12. 웹 서비스를 Android 애플리케이션에 연결하는 방법
- 13. Android 애플리케이션과 웹 서비스를 연결하는 방법은 무엇입니까?
- 14. Node.js 용 Google 애플리케이션을 웹 애플리케이션에 통합하는 방법은 무엇입니까?
- 15. 내 레이아웃에 ACHARTENGINE을 통합하는 방법은 무엇입니까?
- 16. Google 어스 API를 데스크톱 애플리케이션에 통합하는 방법은 무엇입니까?
- 17. 내 애플리케이션에 위젯을 추가하십시오 .- Android
- 18. (Qt) 애플리케이션에 광고를 통합하는 솔루션
- 19. Android 애플리케이션에 키보드를 표시하는 방법은 무엇입니까?
- 20. Android 애플리케이션에 맞춤 단축키를 만드는 방법은 무엇입니까?
- 21. Google App Engine을 기존 웹 애플리케이션에 통합하는 방법은 무엇입니까?
- 22. Android 서비스를 제어하는 방법은 무엇입니까?
- 23. Android 애플리케이션에 기부 기능을 구현하는 방법은 무엇입니까?
- 24. Android 애플리케이션에 아이콘을 추가하는 방법은 무엇입니까?
- 25. Android 애플리케이션에 LinkedList를 저장하는 쉬운 방법은 무엇입니까?
- 26. Gmail/yahoo 등에서 메일/주소록을 가져 오는 방법은 무엇입니까?
- 27. Scala를 핵심 Android 플랫폼에 통합하는 방법은 무엇입니까?
- 28. 어떻게 Android 애플리케이션에 Twitter를 통합합니까?
- 29. 내 사이트에 vBulletin 인증을 통합하는 방법은 무엇입니까?
- 30. 내 ios 앱에 Alfresco를 통합하는 방법은 무엇입니까?
귀하의 질문이 너무 막연합니다. Yahoo는 회사입니다. 야후의 어떤 서비스를 통합하고 싶습니까? 지금까지 뭐 해봤 어? –
ZI가 설명 할 수없는 미안하지만 내 로그인 –