0

Retriving contacts from Yahoo address book using java

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.......

by
10 Replies
  • 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
    0
  • The same problem is with me too, getting same error
    In case you people find any solution, please share it across.
    Thanks in advance...
    0
  • 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
    0
  • 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
    0
  • 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.
    0
  • 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.
    0
  • Please send me the the Above application code to srihari_sirumalla@yahoo.com
    Please send me ASAP


    QUOTE(Kings @ 5 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
    0
  • Please send me the above application code to srihari_sirumalla@yahoo.com
    0
  • Hi Srihari,

    If you have got the java code to import the yahoo contacts please forward me also the same.
    Your help would highly be appreciated

    regards,
    Lav.


    QUOTE(Srihari @ 4 Oct 2012 5:32 AM)
    Please send me the above application code to srihari_sirumalla@yahoo.com
    0
  • Hi Team
    If you could complete the coding for importing the contacts from the yahoo, please send those to me too at mrmuralikrishnam@yahoo.com.
    0

Recent Posts

in Java Development