gpt4 book ai didi

java - 如何在 Android 中检索雅虎联系人?

转载 作者:行者123 更新时间:2023-12-01 04:42:02 25 4
gpt4 key购买 nike

我是 Android 新手。我正在实现用于检索雅虎联系人的应用程序 在我的应用程序中。但是当我运行应用程序时成功登录 然后点击同意分享信息,但我面临着这些类型的 错误-

Authentication error: Unable to respond to any of these challenges: 
{oauth=WWW-Authenticate: Oath oath_problem="signature_invalid", realm="yahooapis.com"}

error while fetching user contact

有人可以帮我吗?这是我的代码:

<小时/>
   private void getAllContacts() throws UnsupportedEncodingException,ClientProtocolException, IOException 
{
HttpClient httpclient = new DefaultHttpClient();

String host_url = "http://social.yahooapis.com/v1/user/" + mUSER_GUID+ "/contacts";

String nonce = ""+System.currentTimeMillis();
String timeStamp = ""+(System.currentTimeMillis()/1000L);

try{
String params =
""+encode("oauth_consumer_key")+"=" + encode(CONSUMER_KEY)
+ "&"+encode("oauth_nonce")+"="+encode(nonce)
+ "&"+encode("oauth_signature_method")+"="+encode("HMAC-SHA1")
+ "&"+encode("oauth_timestamp")+"="+encode(timeStamp)
+ "&"+encode("oauth_token")+"="+ACCESS_TOKEN
+ "&"+encode("oauth_version")+"="+encode("1.0")

;
String baseString = encode("GET")+"&"+encode(host_url)+"&"+encode(params);
String signingKey = encode(CONSUMER_SECRET)+"&"+encode(ACCESS_TOKEN_SECRET);
Log.e(TAG, "base string: " + baseString);
String lSignature = computeHmac(baseString, signingKey);
Log.e(TAG, "signature: " + lSignature);
lSignature = encode(lSignature);
Log.e(TAG, "signature enacoded: " + lSignature);

String lRequestUrl = host_url
+ "?oauth_consumer_key="+CONSUMER_KEY
+ "&oauth_nonce="+nonce
+ "&oauth_signature_method=HMAC-SHA1"
+ "&oauth_timestamp="+timeStamp
+ "&oauth_token="+ACCESS_TOKEN
+ "&oauth_version=1.0"
+ "&oauth_signature="+lSignature
;
Log.e(TAG, lRequestUrl);



HttpGet httpget = new HttpGet(lRequestUrl);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
responseBody = httpclient.execute(httpget, responseHandler);
Log.e(TAG, "contacts response: " + responseBody);


String strUrl=responseBody;
DefaultHttpClient httpClient=new DefaultHttpClient();
HttpPost httppost=new HttpPost(strUrl);
HttpResponse httpresponse=httpClient.execute(httppost);
HttpEntity httpEntity=httpresponse.getEntity();

String strXml=EntityUtils.toString(httpEntity);

ArrayList<HashMap<String , String>> arrayList=new ArrayList<HashMap<String,String>>();

XMLParser xmlparser=new XMLParser();
String strxml = xmlparser.getXmlFromUrl(responseBody);
Log.e("",""+strxml); // getting xml url here
Document doc = xmlparser.getDomElement(strxml); // getting data object model
NodeList nl = doc.getElementsByTagName(KEY_FIELD); // Looping through all item nodes <field>

for(int i=0 ; i<nl.getLength() ; i++ )
{
//creating new hash map
HashMap<String ,String > map = new HashMap<String, String>();
Element e = (Element) nl.item(i);

//Adding each child node to HashMap Key Value pair
map.put(KEY_ID , xmlparser.getValue(e, KEY_ID));
map.put(KEY_TYPE , xmlparser.getValue(e, KEY_TYPE));
map.put(KAE_VALUE , xmlparser.getValue(e, KAE_VALUE));

Log.e("Hash Map","Key Value"+map);

//Adding hashlist to arrayList
arrayList.add(map);
Log.e("ArrayList ","of Contact "+arrayList);
}



}

catch(Exception e)
{
e.printStackTrace();
Log.e(TAG, "error while fetching user contacts");
}


}

提前致谢。

最佳答案

参见K-9 mail 。 K-9 是开源的。

关于java - 如何在 Android 中检索雅虎联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16371176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com