1

I've been working with the iTunes search API to get the content from iTunes to display on my site which returns JSON data that I'm storing in the database and then displaying the data from my database. I'll be using linkshare to affiliate my links of the product to the iTunes Store. The problem I'm facing is when I save my data to the database I'm saving the iTunes URL of the product in the database (which isn't affiliated) and I'm wondering if there is away that I can integrate the linkshare affiliate link to my search API so I don't have to manually setup the affiliate link for each product every time. Thanks in advance, I appreciate the advice!

iTunes Search API URL

http://itunes.apple.com/search?term='.$term.'&limit=5&media=software&enity=software

URL RETURNED

https://itunes.apple.com/us/app/angry-birds-seasons/id398157641?mt=8&ign-mpt=uo%3D4%2522

AFFILIATE URL REQUIRED

http://click.linksynergy.com/fs-bin/stat?id=yfbyIWqHFt8&offerid=146261&type=3&subid=0&tmpid=1826&RD_PARM1=https%253A%252F%252Fitunes.apple.com%252Fus%252Fapp%252Fangry-birds-seasons%252Fid398157641%253Fmt%253D8%2526uo%253D4%2526partnerId%253D30
Mitchell Layzell
  • 3,058
  • 3
  • 20
  • 33
  • How to get apps details from iTunes? I searching this topic but i can't find.. can you help me? –  Jun 13 '14 at 05:07
  • @Guru to get the app's details use the first link in my question, just submit a form and use the term the user entered for the $term variable and that will return JSON data that you can access, for an example goto this link in your browser and you'll see it returns the JSON data of the apps that are found off the keyword angry birds. http://itunes.apple.com/search?term=angrybirds&limit=5&media=software&enity=software e-mail me if you're still having issues I can send you a basic example if you need. – Mitchell Layzell Jun 14 '14 at 05:51
  • Thank you @Mitch I got answer... –  Jun 17 '14 at 04:04

2 Answers2

2

It seems like your affiliate URL equals :

http://click.linksynergy.com/fs-bin/stat?id=yfbyIWqHFt8&offerid=146261&type=3&subid=0&tmpid=1826&RD_PARM1=+url component encode returned

To make it so :

in JS

encodeURIComponent(
     encodeURIComponent(
         'https://itunes.apple.com/us/app/angry-birds-seasons/id398157641?mt=8&ign-mpt=uo%3D4%2522'
      )
);

would give you

https%253A%252F%252Fitunes.apple.com%252Fus%252Fapp%252Fangry-birds-seasons%252Fid398157641%253Fmt%253D8%2526ign-mpt%253Duo%25253D4%25252522

which seems to be the missing part in your affiliate URL. (without the partnerId%253D30)

in PHP

From https://stackoverflow.com/a/1734255/460368, you can have this function which will do the same thing as in JS :

function encodeURIComponent($str) {
    $revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
    return strtr(rawurlencode($str), $revert);
}

So,

echo encodeURIComponent(
         encodeURIComponent(
             'https://itunes.apple.com/us/app/angry-birds-seasons/id398157641?mt=8&ign-mpt=uo%3D4%2522'
         )
     );

will give you

https%253A%252F%252Fitunes.apple.com%252Fus%252Fapp%252Fangry-birds-seasons%252Fid398157641%253Fmt%253D8%2526ign-mpt%253Duo%25253D4%25252522

Community
  • 1
  • 1
Shikiryu
  • 10,180
  • 8
  • 49
  • 75
0

I`m using the json api from iTunes. So i just get that information and then do a little explode, like:

$download_link = $results->trackViewUrl;
$download_link = explode('uo=4", $download_link);
$download_link = $download_link[0].'partnerId=30&siteID=';

After siteID place your affiliate ID and that should make your link.