Vyew Discussion Forum

You must be a registered Vyew member to post in the forum. Login or Register for free
If you just logged in, you may need to refresh this page.
   
 
Calling API with Java ( Getting “0|Access denied (702)” as response)
Posted: 22 September 2009 03:41 AM   Ignore ]  
New User
Rank
Total Posts:  6
Joined  2009-09-17

I am accessing View API through a HTTP Rest Call from a java class. I am getting the response as
“0|Access denied (702)”

Please help me.

MY Code is as follows:

package org.demo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;

import javax.net.ssl.HttpsURLConnection;

public class VyewTest {

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String sCmd = “login”;

String sResult = VyewAPI(sCmd);
System.out.println(sResult);
String[] sSplitResult = sResult.split("|");
if (sSplitResult[0].trim() == “1")
{

String sCode = sSplitResult[1];
String sURL = sSplitResult[2];

}
else
{
//API failed

System.out.println("Vyew API failed, retval=” + sResult);

}

}

private static String VyewAPI(String sCmd) throws IOException
{
String sApiUrl = “https://vyew.com/api”;
String sKey = “MY_API_KEY”; //my Vyew API key //e7353293b1
String sSecret = “MY_API_SECRET”; //my Vyew API secret phrase
long nEpochTime = new Date().getTime()/1000;
String email= “MY_ACCOUNT_EMAIL_ID”;
String pw="MY_ACCOUNT_PASSWORD";

String sQ = “cmd=” + sCmd;



sQ += ("&email;="+email);
sQ += ("&pass;="+pw);


sQ += ("&key;=" + sKey);
sQ += ("&time;=" + Long.toString(nEpochTime));


String sMD5 = GetMD5Hash(sQ + sSecret);
String sURL = sApiUrl + “?” + sQ + “&md5;=” + sMD5;

String postData = “dbQuery=” + URLEncoder.encode(sURL, “UTF-8");
System.out.println(sURL);

String sResponse = “”;

URL u = new URL(sURL);
URLConnection uc = (URLConnection) u.openConnection();

uc.setDoOutput(true);
uc.setUseCaches(false);

uc.setRequestProperty("Content-type”,"application/xhtml+xml");
uc.setRequestProperty("Content-length", “” + postData.length());


BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
// Read it ...

while ((sResponse = in.readLine()) != null)
System.out.println("inputLine------> “+sResponse);

in.close();

return sResponse;
}




public static String GetMD5Hash(String sInputString)
{
// Returns a hash (message digest) of the input String.
// See internet RFC 1321, “The MD5 Message-Digest Algorithm”

//Convert the String into an array of bytes.
byte[] buffer=null;
String sResult = “”;
try {
buffer = sInputString.getBytes("ASCII");


//Create the md5 hash provider.

MessageDigest md= MessageDigest.getInstance("MD5");



//Compute the hash value from the array of bytes.
md.update(buffer);
byte[] hash = md.digest();



int msb;
int lsb = 0;
int i;

// MSB maps to idx 0
final char[] hexChars ={’0’,’1’,’2’,’3’,’4’,’5’,’6’,’7’,’8’,’9’,’A’,’B’,’C’,’D’,’E’,’F’};

for (i = 0; i < hash.length; i++){
msb = ((int)hash & 0x000000FF) / 16;
lsb = ((int)hash & 0x000000FF) % 16;
sResult = sResult + hexChars[msb] + hexChars[lsb];
}

} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sResult;

}

}

Profile
 
Posted: 23 September 2009 07:20 AM   Ignore ]   [ # 1 ]  
New User
Rank
Total Posts:  6
Joined  2009-09-17

The code is working with some changes .

Will update soon after doing some Testing.

Thanks

Profile
 
Posted: 17 December 2009 07:44 AM   Ignore ]   [ # 2 ]  
New User
Rank
Total Posts:  1
Joined  2009-12-16

^i hope you update soon. I’m having the same issues right now.

Regards,
Corbie
Simulation pret immobilier

Profile
 
Posted: 17 December 2009 08:45 AM   Ignore ]   [ # 3 ]  
New User
Rank
Total Posts:  6
Joined  2009-09-17

Please check the timestamp on your from where you are running the code.

Thanks

Profile
 
Posted: 17 December 2009 08:45 AM   Ignore ]   [ # 4 ]  
New User
Rank
Total Posts:  6
Joined  2009-09-17

Please check the timestamp on your system from where you are running the code.

Thanks

Profile