将Ebay Link Generator结果转换为bitly.com链接 [英] Convert Ebay Link Generator results into bitly.com link

查看:217
本文介绍了将Ebay Link Generator结果转换为bitly.com链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我管理了一个小的PHP脚本,它将搜索ebay产品并将其转换为推广ebay链接。



它就像那样 - 用户搜索例如:ocz vertex

点击提交并获得结果:


http: //rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=10&pub=5575165347&toolid=10001&campid=5337851510&customid=&icep_uq=ocz
vertex& 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


(无法修复ocz和顶点字之间生成的链接中的空格)



现在,结果很好,但我想通过其API 的.comrel =noreferrer> bitly.com 帐户。

基本上我希望它生成并将完整的ebay链接结果转换为小的bitly.com链接( http:// ebay .to / 2scU91k 例如)并在我的帐户上看到该链接。



过程如下:
用户搜索term喜欢ocz vertex - >点击提交 - >获取ebay.to短链接(当真正的进程在后台时,转换为rover.ebay.com地址,然后使用我的bitly.com凭据转换为ebay.to) / p>

我找到了那个 ,尤其是但没有得到我如何实现结果作为一个新的点转换。



这里是PHP代码:

 <!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 =stylesheettype =text / csshref =css / screen.css>
< style type =text / css>
body {
margin:0px;
字体大小:0.7em;
font-family:trebuchet ms;
颜色:#222;
}
#mainContainer {
宽度:840px;
保证金:5px;
}
table,tr,td {
vertical-align:top;
}
.textInput {
宽度:300px;
}
html {
margin:0px;
}
.formButton {
宽度:75px;
}
textarea,输入,选择{
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 =内容突出显示并复制到剪贴板!
setTimeout(window.status ='',1800)
}
}
// - >
< / script>


< / head>
< table width =80%height =100pxalign =centerstyle =margin:0 auto>< tr>< td align =center>
< h2> Link Generator Online< / h2>
< / td>< tr>< / table>
< table width =80%align =centerstyle =margin:0 auto>< tr>< td align =center>
< / div>

< / td>< td valign =top>
< form action =<?php echo $ _SERVER ['PHP_SELF'];?>方法= POST >
< br>
网址< br>
< input type = text style =font-size:13px; font-family:tahoma,arial; font-weight:bold; color:#000000; BORDER:#555 1px solid; BACKGROUND-COLOR:# FFF输入名称=urlsize =20>
< br>

< br>
< input type =SUBMITname =submitVALUE =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 \>无效字符。< / center>;
Die();
}
if(ereg(\<,$ url)){
echo< br>< center>< font color = \red \ >无效字符。< / center>;
Die();
}
if(ereg(\ [,$ url)){
echo< br>< center>< font color = \red \ >无效字符。< / center>;
Die();
}
if(ereg(\',$ url)){
echo< br>< center>< font color = \red \ >无效字符。< / center>;
Die();
}
if(ereg(\#,$ url)){
echo< br>< center>< font color = \red \ >无效字符。< / center>;
Die();
}
if(ereg(\`,$ url)){
echo< br>< center>< font color = \red \ >无效字符。< / center>;
Die();
}

if(!strlen($ url)){
echo< br>< center>< font color = \red \> ;空场。< / center>;

Die();
}
if(strlen($ url)> 100){
echo< br>< center>< font color = \red \> The字段不得超过150个字符。< / center>;

Die();
}
}
?>
< br>
< center>
< form name =vini>
< a class =highlighttexthref =javascript:HighlightAll('vini.select1')>选择全部< / a>< br>
< textarea name =select1rows = 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>

参见直播 易趣链接生成器

解决方案

我构建了一个没有外部库的小型解决方案。它基本上归结为:




  • 从注册应用程序仪表板或oauth API中的oauth令牌获取API密钥

  • 使用您的令牌和网址向 / v3 /缩短 API端点发出请求



第一步:获取令牌



您只需要执行一次此操作。 Bitly的文档列出了一些使用卷曲的方法,我认为这是最简单的方法。您还可以使用PHP 。只需发出此POST请求(从这里 ):

  curl -u用户名:密码-X POSThttps://api-ssl.bitly.com/oauth/access_token

结果是这样的:

  e663e30818201d28dd07803e57333bed4f15803a 

这是你的代币。



第二步:发出请求



将令牌和url编码的URL插入到 / v3 /缩短 端点:

 <?php 
$ ebay_url =http://rover.ebay.com/rover/1/711-53200-19255-0/1 ?icep_ff3 = 10安培;酒馆= 5575165347&安培; toolid = 10001&安培; campid = 5337851510&安培;的自订=安培; 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; //更改此
$ 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;
?>

API调用的结果是JSON,需要解码。一个例子是在文档中。此代码示例未考虑API超时或可能发生的其他错误(例如令牌到期,目前不是问题



完整代码:

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd > 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< link rel =stylesheettype =text / csshref =css / screen.css>
< style type =text / css>
body {
margin:0px;
字体大小:0.7em;
font-family:trebuchet ms;
颜色:#222;
}
#mainContainer {
宽度:840px;
保证金:5px;
}
table,tr,td {
vertical-align:top;
}
.textInput {
宽度:300px;
}
html {
margin:0px;
}
.formButton {
宽度:75px;
}
textarea,输入,选择{
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 =内容突出显示并复制到剪贴板!
setTimeout(window.status ='',1800)
}
}
// - >
< / script>


< / head>
< table width =80%height =100pxalign =centerstyle =margin:0 auto>< tr>< td align =center>
< h2> Link Generator Online< / h2>
< / td>< tr>< / table>
< table width =80%align =centerstyle =margin:0 auto>< tr>< td align =center>
< / div>

< / td>< td valign =top>
< form action =<?php echo $ _SERVER ['PHP_SELF'];?>方法= POST >
< br>
插入关键字:< br>
< input type = text style =font-size:13px; font-family:tahoma,arial; font-weight:bold; color:#000000; BORDER:#555 1px solid; BACKGROUND-COLOR:# FFF输入名称=urlsize =20>
< br>

< br>
< input type =SUBMITname =submitVALUE =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 \>无效字符。< / center>;
Die();
}
if(!strlen($ url)){
echo< br>< center>< font color = \red\>空字段。 < /中心>中;
Die();
}
if(strlen($ url)> 100){
echo< br>< center>< font color = \red \> The字段不得超过150个字符。< / center>;
Die();
}
}

$ ebay_url =http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=10&酒馆= 5575165347&放大器; toolid = 10001&放大器; campid = 5337851510&放大器;的自订=安培; icep_uq = 进行urlencode($网址)。与 & icep_sellerId =安培; icep_ex_kw =安培; icep_sortBy = 15安培; icep_catId =安培; icep_minPrice =安培; icep_maxPrice =&安培; IPN = psmain&安培; icep_vectorid = 229466&安培; KWID = 902099&安培; MTID = 824&安培;千瓦= 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 =highlighttexthref =javascript:HighlightAll('vini.select1')>选择全部< / a>< br>
< textarea name =select1rows = 3 cols = 75 style =font-family:tahoma; color:#555; border:1px dashed #ccc>
<?php echo $ short_url; ?>
< / textarea>
< br>
< / form>

<?php
}
?>
< / body>
< / html>

注意:我更改了您的 ereg 来电 preg_match 与PHP7兼容,并使用正则表达式缩短 if 。我还使用了 urlencode($ url),这样空格就不会破坏链接。


I managed a small PHP script that takes the ebay product searched and convert it into promote ebay link.

It goes like that- user search for example: ocz vertex
Clicks on "Submit" and get the results:

http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=10&pub=5575165347&toolid=10001&campid=5337851510&customid=&icep_uq=ocz vertex&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

(Cant fix that space in the link generated between ocz and vertex words)

Now, the result is nice but i want to short it via bitly.com account using their API.
Basicly i want it to generate and convert the full ebay link results into small bitly.com link (http://ebay.to/2scU91k for example) and to see that link on my bitly account.

The process go like that: User search for term like ocz vertex -> click on "Submit" -> Get the ebay.to short link (while the real process is in background, converts to rover.ebay.com address and then to ebay.to using my bitly.com credentials)

I found that and that and especially that but didnt get how do i implement the results as a new bitly convert.

Here's 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>

See on live: Ebay link Generator

解决方案

I built a small solution that works without external libraries. It essentially boils down to this:

  • Acquire an API key from the "Register an application" dashboard or an oauth token from the oauth API
  • Make the request to the /v3/shorten API endpoint with your token and URL

First step: Get the token

You only need to do this once. Bitly's documentation lists a few examples how you can do it using curl, I think that is the easiest way. You could also do it with PHP. Simply make this POST request (taken from here):

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

The result is something like this:

e663e30818201d28dd07803e57333bed4f15803a

That is your token.

Second step: Make the request

Insert the token and url-encoded URL into the HTTP request to 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 needs to be decoded. An example is in the documentation. This code example does not take into consideration API timeouts or other errors that might occur (such as token expiry, which is currently not an issue).

The complete 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 the ifs with a regular expression. I also used urlencode($url) so that spaces won't break the link.

这篇关于将Ebay Link Generator结果转换为bitly.com链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆