大家好我想在我的Android應用程序中集成雅虎郵件服務。谷歌搜索後,我沒有得到適當的教程,請任何人提供任何鏈接或建議,這對我有幫助如何在我的Android應用程序中集成雅虎郵件服務?
0
A
回答
3
看到上面的soure代碼其工作正常並下載Oauth Libary。
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 ..可以告訴我..你有任何演示的雅虎集成的Android。 – 2012-09-26 05:32:40
+0
http://code.google.com/p/oauth-signpost/downloads/list – 2012-09-26 05:46:57
+0
嗨,感謝您的回覆確實有任何完整的雅虎登錄Android的示例... – 2012-09-26 06:03:10
相關問題
- 1. 我想雅虎在我的iPhone應用程序中集成
- 2. 雅虎Android中的集成
- 3. 如何讓雅虎郵件進入Android應用程序
- 4. NoClassDefFoundError同時在應用程序中集成雅虎
- 5. 我的雅虎應用程序教程
- 6. 如何在android應用程序中集成Web服務器?
- 7. 編寫應用程序,將捕獲用戶和雅虎郵件傳遞,如果權利去雅虎郵箱
- 8. 我如何發送郵件從雅虎和其他人在Android
- 9. 如何使響應電子郵件與雅虎手機應用程序工作?
- 10. 通過Android和iPhone應用程序集成雅虎,谷歌和openid嗎?
- 11. 雅虎郵件api與php在oauth集成
- 12. hello.js雅虎API集成
- 13. 如何通過雅虎iPhone應用程序連接到雅虎通?
- 14. 雅虎應用程序的Netbeans intellisense
- 15. 如何登錄MyAdmin雅虎服務器
- 16. 未能檢索雅虎集成在android中的請求令牌?
- 17. 雅虎郵件與PHP
- 18. 雅虎應用程序認證Laravel
- 19. 無法創建雅虎應用程序
- 20. 雅虎天氣Web服務
- 21. uitableview在雅虎郵件應用程序的頭部下時淡出單元格
- 22. 如何在我的android應用程序中使用服務?
- 23. 如何將XMPP服務器與臉書和雅虎的iPhone集成?
- 24. 谷歌,Facebook,雅虎oauth/oauth2在Android應用程序
- 25. 如何停止我的應用程序在android中的服務?
- 26. 使用CalDav API集成雅虎日曆
- 27. 認證錯誤發送郵件從雅虎在C#窗口應用程序
- 28. 集成SendGrid SMTP服務,讓空的郵件雅虎和yopmail但接收在Gmail,Hotmail和Rediff的
- 29. 導入雅虎接觸到的Android應用程序
- 30. 如何解析來自雅虎服務器的json響應?
您的問題太含糊。雅虎是一家公司。您希望整合哪種雅虎服務?你試過什麼了? – 2012-04-07 04:48:43
對不起我的努力,其中ZI不能解釋你,但我想在登錄後打開雅虎郵件服務 – 2012-04-07 05:01:26