Convert eBay Link Generator Results to bitly.com Link

I ran a small PHP script that takes the desired eBay product and converts it into an eBay promotion link.

It looks like this:

  1. user searches for example: ocz vertex
  2. clicks "Submit" and receives the results in the following format

Http://rover.ebay.com/rover/1/711-53200-19255-0/1 = ip_t_p_p0_p0_p0 = psmain & icep_vectorid = 229466 & kwid = 902099 & mtid = 824 & kW = L.G.

(It is not possible to fix this space in the link generated between the words ocz and vertex)

Now the result is good, but I want to reduce it through the bitly.com account using their API .
Essentially, I want it to generate and convert the full results of the eBay link into a small bitly.com link (for example, http://ebay.to/2scU91k ) and see this link in my bitly account.

The process will go like this:

  • Custom search for term as ocz vertex
  • Click Submit
  • get a short link to ebay.to (while the real process is in the background, it will be converted to rover.ebay.com and then to ebay.to using my bitly.com credentials)

I found this and this, and especially this , but did not understand how to implement the results as a new slightly transformed one.

Here is the PHP code:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="css/screen.css"> <style type="text/css"> body{ margin:0px; font-size:0.7em; font-family:trebuchet ms; color:#222; } #mainContainer{ width:840px; margin:5px; } table,tr,td{ vertical-align:top; } .textInput{ width:300px; } html{ margin:0px; } .formButton{ width:75px; } textarea,input,select{ font-family:helvetica; } i{ font-size:0.9em; } </style> <script language="Javascript"> <!-- var copytoclip=1 function HighlightAll(theField) { var tempval=eval("document."+theField) tempval.focus() tempval.select() if (document.all&&copytoclip==1){ therange=tempval.createTextRange() therange.execCommand("Copy") window.status="Contents highlighted and copied to clipboard!" setTimeout("window.status=''",1800) } } //--> </script> </head> <table width="80%" height="100px" align="center" style="margin:0 auto"><tr><td align="center"> <h2>Link Generator Online</h2> </td><tr></table> <table width="80%" align="center" style="margin:0 auto"><tr><td align="center"> </div> </td><td valign="top"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <br> URL<br> <input type=text style="font-size: 13px; font-family: tahoma,arial; font-weight: bold; color: #000000; BORDER: #555 1px solid ; BACKGROUND-COLOR: #FFF" input name="url" size="20"> <br> <br> <input type="SUBMIT" name="submit" VALUE="Submit"> </form> </td></tr></table> <?php if(isset($_POST['submit'])){ $url = $_POST['url']; $name=array($url); foreach ($name as $name) { if (ereg("^\.",$url)) { echo "<br><center><font color=\"red\">Invalid Characters.</center>"; Die(); } if (ereg("\<", $url)) { echo "<br><center><font color=\"red\">Invalid Characters.</center>"; Die(); } if (ereg("\[", $url)) { echo "<br><center><font color=\"red\">Invalid Characters.</center>"; Die(); } if (ereg("\'", $url)) { echo "<br><center><font color=\"red\">Invalid Characters.</center>"; Die(); } if (ereg("\#", $url)) { echo "<br><center><font color=\"red\">Invalid Characters.</center>"; Die(); } if (ereg("\'", $url)) { echo "<br><center><font color=\"red\">Invalid Characters.</center>"; Die(); } if (!strlen($url)) { echo "<br><center><font color=\"red\">Empty Field.</center>"; Die(); } if (strlen($url) > 100) { echo "<br><center><font color=\"red\">The field cannot contain more than 150 characters.</center>"; Die(); } } ?> <br> <center> <form name="vini"> <a class="highlighttext" href="javascript:HighlightAll('vini.select1')">Select All</a><br> <textarea name="select1" rows=3 cols=75 style="font-family:tahoma;color:#555;border:1px dashed #ccc"> http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=10&pub=5575165347&toolid=10001&campid=5337851510&customid=&icep_uq=<?php echo $url ?>&icep_sellerId=&icep_ex_kw=&icep_sortBy=15&icep_catId=&icep_minPrice=&icep_maxPrice=&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg </textarea> <br> </form> <?php } ?> </body> </html> 

Watch live : Ebay Link Generator

+5
source share
1 answer

I built a small solution that works without external libraries. Essentially, it boils down to the following:

  • Get the API key from the Application Registration panel or the oauth token from the oauth API
  • Request API endpoint /v3/shorten with your token and url

First step: Get a token

You only need to do this once. The documentation battle lists a few examples of how you can do this using curl , I think this is the easiest way. You can also do this with PHP . Just make this POST request (made from here ):

 curl -u "username:password" -X POST "https://api-ssl.bitly.com/oauth/access_token" 

The result looks something like this:

 e663e30818201d28dd07803e57333bed4f15803a 

This is your token.

Second step: make a request

Paste the URL of the token and the URL into the HTTP request at the /v3/shorten endpoint:

 <?php $ebay_url = "http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=10&pub=5575165347&toolid=10001&campid=5337851510&customid=&icep_uq=ocz%20vertex&icep_sellerId=&icep_ex_kw=&icep_sortBy=15&icep_catId=&icep_minPrice=&icep_maxPrice=&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg" $token = "e663e30818201d28dd07803e57333bed4f15803a"; // change this $endpoint = "https://api-ssl.bitly.com/v3/shorten?access_token=".$token."&longUrl=".urlencode($ebay_url).""; $result = file_get_contents($endpoint); $json = json_decode($result, true); $short_url = $json["data"]["url"]; echo $short_url; ?> 

The result of the API call is JSON and must be decoded. An example is given in the documentation. This code example does not take into account API timeouts or other errors that may occur (for example, the expiration of a token, which is currently not a problem ).

Full code:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="css/screen.css"> <style type="text/css"> body{ margin:0px; font-size:0.7em; font-family:trebuchet ms; color:#222; } #mainContainer{ width:840px; margin:5px; } table,tr,td{ vertical-align:top; } .textInput{ width:300px; } html{ margin:0px; } .formButton{ width:75px; } textarea,input,select{ font-family:helvetica; } i{ font-size:0.9em; } </style> <script language="Javascript"> <!-- var copytoclip=1 function HighlightAll(theField) { var tempval=eval("document."+theField) tempval.focus() tempval.select() if (document.all&&copytoclip==1){ therange=tempval.createTextRange() therange.execCommand("Copy") window.status="Contents highlighted and copied to clipboard!" setTimeout("window.status=''",1800) } } //--> </script> </head> <table width="80%" height="100px" align="center" style="margin:0 auto"><tr><td align="center"> <h2>Link Generator Online</h2> </td><tr></table> <table width="80%" align="center" style="margin:0 auto"><tr><td align="center"> </div> </td><td valign="top"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <br> Insert keywords:<br> <input type=text style="font-size: 13px; font-family: tahoma,arial; font-weight: bold; color: #000000; BORDER: #555 1px solid ; BACKGROUND-COLOR: #FFF" input name="url" size="20"> <br> <br> <input type="SUBMIT" name="submit" VALUE="Submit"> </form> </td></tr></table> <?php if(isset($_POST['submit'])){ $url = $_POST['url']; $name = array($url); foreach ($name as $name) { if (preg_match("/^[\.\<\[#`]/",$url)) { echo "<br><center><font color=\"red\">Invalid Characters.</center>"; Die(); } if (!strlen($url)) { echo "<br><center><font color=\"red\">Empty Field.</center>"; Die(); } if (strlen($url) > 100) { echo "<br><center><font color=\"red\">The field cannot contain more than 150 characters.</center>"; Die(); } } $ebay_url = "http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=10&pub=5575165347&toolid=10001&campid=5337851510&customid=&icep_uq=".urlencode($url)."&icep_sellerId=&icep_ex_kw=&icep_sortBy=15&icep_catId=&icep_minPrice=&icep_maxPrice=&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg"; $token = "e663e30818201d28dd07803e57333bed4f15803a"; $endpoint = "https://api-ssl.bitly.com/v3/shorten?access_token=".$token."&longUrl=".urlencode($ebay_url); $result = file_get_contents($endpoint); $json = json_decode($result, true); $short_url = $json["data"]["url"]; ?> <br> <center> <form name="vini"> <a class="highlighttext" href="javascript:HighlightAll('vini.select1')">Select All</a><br> <textarea name="select1" rows=3 cols=75 style="font-family:tahoma;color:#555;border:1px dashed #ccc"> <?php echo $short_url; ?> </textarea> <br> </form> <?php } ?> </body> </html> 

Note. I changed your ereg calls to preg_match for compatibility with PHP7 and shortened if with a regex. I also used urlencode($url) so that spaces do not break the link.

+2
source

Source: https://habr.com/ru/post/1269356/


All Articles