2013-05-04 77 views
0

我是Android新手。我执行的应用程序,用于检索雅虎接触 在我application.But当我运行该应用程序成功登录 并点击同意共享信息,但我面对这些类型的 无差错如何检索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"); 
     } 


    } 

在此先感谢。

回答

0

请参阅K-9 mail。 K-9是一个开源软件。

+0

我有签名错误无效。我还没有在您的K-9邮件示例中找到任何解决方案。 – TJM 2013-05-04 07:26:05