私はアンドロイドが初めてです。アプリケーションでヤフーの連絡先を取得するためのアプリを実装していますが、アプリケーションを正常に実行すると、ログインして同意をクリックして情報を共有しますが、これらのタイプのエラーに直面します-
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");
}
}
前もって感謝します。