Hi guys. Anyone who has experience with developing...
# contributing-to-airbyte
t
Hi guys. Anyone who has experience with developing Shopify auth app and connecting to airbyte ?
u
hi tharaka, you should be able to use just an API key
u
we’re going to add oauth support to shopify soon so you should be able to pass in oauth creds
u
do you implement shopify connect like this ?? https://agencyanalytics.com
u
What do you mean?
t
in this site we can connect shopify using install app
u
that experience will be available in airbyte cloud
t
airbyte OSS you’ll need to setup the oauth app yourself
u
im waiting list in airbyte cloud. when do we can access it ??
u
Copy code
private String getAccessToken(String shopName, String code) {
   try {
      String urlParameters  = "client_id="+ ShopifyClientId +"&client_secret="+ ShopifySecret +"&code=" + code;
      byte[] postData       = urlParameters.getBytes( StandardCharsets.UTF_8 );
      int    postDataLength = postData.length;
      
      URL url = new URL("https://"+shopName+".<http://myshopify.com/admin/oauth/access_token%22|myshopify.com/admin/oauth/access_token">);

      // Open a connection(?) on the URL(??) and cast the response(???)
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
     
      connection.setRequestMethod("POST");
      connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      connection.setDoOutput( true );
      connection.setInstanceFollowRedirects( false );
      connection.setRequestProperty( "charset", "utf-8");
      connection.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
      connection.setUseCaches( false );
      // Now it's "open", we can set the request method, headers etc.
      connection.setRequestProperty("accept", "application/json");
      try( DataOutputStream wr = new DataOutputStream( connection.getOutputStream())) {
         wr.write( postData );
      }

      String inputLine, readline = "";
   
      // reading the HTML output of the GET HTTP request
      BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      while ((inputLine = in.readLine()) != null) {
         readline = readline + inputLine;
      }
      in.close();
      return readline;
    } catch (Exception e) {
       log.error("Exception occurred when try to getAccessToken : ", e);
       return null;
    }
}
k
Copy code
String responseJsonString = getAccessToken(shopName, code);

if (!StringUtils.isEmpty(responseJsonString)) {
   
   JSONObject responseJson = new JSONObject(responseJsonString);
   
   if (responseJson.has("access_token")) {
      
      String accessToken = responseJson.get("access_token").toString();
u
You can adapt the above code..
u
DM me if you need help