Retriving contacts from Yahoo address book using java

sal30 Jun 2009 4:25 AM
Hi... want to import contacts from yahoo address book using java. Been able to get wssid and cookie but not able to move further with the following code using java:-


String req ="http://address.yahooapis.com/api/ws/v1/searchContacts?"+
"format=xml&fields=name,email&appid="+appId+"&WSSID="+wssid;
Cookie cookie=new Cookie("Cookie",new String(Base64.encodeBase64(ycookie.getBytes())));

HttpClient client = new HttpClient();
GetMethod method = new GetMethod(req);
response.addCookie(cookie);
// Send GET request
int statusCode = client.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
out.println("method.getStatusLine()-> "+method.getStatusLine());
}
InputStream rstream = null;

// Get the response body
try {
rstream = method.getResponseBodyAsStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
out.println("e "+e);
}

// Process the response from Yahoo! Web Services
BufferedReader br = new BufferedReader(new InputStreamReader(rstream));
String line;
while((line = br.readLine()) != null){%>
<tr>
<td><%=line%></td>
</tr>
<%}%>
</table>

Executing the above code gives the following error:

method.getStatusLine()-> HTTP/1.1 403 Forbidden

Hope to hear soon from your side.......
Mike7 Jul 2009 10:12 AM
hey even I am facing the same problem...I initially thought that I was not setting the cookie properly, but seems like thats not the case. Please let me know if you could find any solution to this problem.

Avan
Verizon Wireless21 Jul 2009 2:50 AM
The same problem is with me too, getting same error
In case you people find any solution, please share it across.
Thanks in advance...
vikas23 Jul 2009 2:04 AM
Hey guys, i did the following thing and it worked like a charm!!!

Remove these lines of code:
Cookie cookie=new Cookie("Cookie",new String(Base64.encodeBase64(ycookie.getBytes())));
response.addCookie(cookie);


As u see we have to send the cookie to the Yahoo! so we have to insert it in the HTTP Header just before calling the executeMethod() method.
use this line of code instead:

method.setRequestHeader("Cookie", ycookie);

Hope this helps.

Cheers,
Vikas
Kings5 Nov 2009 10:43 PM
QUOTE (sal @ Jun 30 2009, 03:25 AM) <{POST_SNAPBACK}>
Hi... want to import contacts from yahoo address book using java. Been able to get wssid and cookie but not able to move further with the following code using java:-


String req ="http://address.yahooapis.com/api/ws/v1/searchContacts?"+
"format=xml&fields=name,email&appid="+appId+"&WSSID="+wssid;
Cookie cookie=new Cookie("Cookie",new String(Base64.encodeBase64(ycookie.getBytes())));

HttpClient client = new HttpClient();
GetMethod method = new GetMethod(req);
response.addCookie(cookie);
// Send GET request
int statusCode = client.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
out.println("method.getStatusLine()-> "+method.getStatusLine());
}
InputStream rstream = null;

// Get the response body
try {
rstream = method.getResponseBodyAsStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
out.println("e "+e);
}

// Process the response from Yahoo! Web Services
BufferedReader br = new BufferedReader(new InputStreamReader(rstream));
String line;
while((line = br.readLine()) != null){%>
<tr>
<td><%=line%></td>
</tr>
<%}%>
</table>

Executing the above code gives the following error:

method.getStatusLine()-> HTTP/1.1 403 Forbidden

Hope to hear soon from your side.......



Hi i'm kingsley,
Have u got the codings for getting the contactlist of yahoo using java.
If so plz send that to my emailID kingsley_samraj@yahoo.co.in
JULIO G7 Apr 2010 7:08 AM
403 - Forbidden: The server understood the credentials, but rejected the request because those credentials are not permitted to execute the requested service. Other than asking the user to log in again under a different appid with different permissions, there is usually not much you can do about this error message.
LAM19 Jun 2010 6:06 PM
I think you could ref from this link : http://lamdaica.com/demo/seeDemo.aspx?id=3&lang=1
QUOTE (JULIO G @ Apr 7 2010, 06:08 AM) <{POST_SNAPBACK}>
403 - Forbidden: The server understood the credentials, but rejected the request because those credentials are not permitted to execute the requested service. Other than asking the user to log in again under a different appid with different permissions, there is usually not much you can do about this error message.