How to get reports from Amazon Affiliate

2019-07-20 01:40发布

问题:

I found this PHP-Oara library https://github.com/fubralimited/php-oara at Github and I've already setup everything.

$networkName = "Amazon"; //Ex: AffiliateWindow
//Retrieving the credentials for the network
$config = Zend_Registry::getInstance()->get('credentialsIni');

$configName = strtolower($networkName);
$credentials = $config->$configName->toArray();

//Path for the cookie located inside the Oara/data/curl folder
$credentials["cookiesDir"] = "example";
$credentials["cookiesSubDir"] = $networkName;
$credentials["cookieName"] = "test";

//The name of the network, It should be the same that the class inside Oara/Network
$credentials['networkName'] = $networkName;
//Which point of view "Publisher" or "Advertiser"
$credentials['type'] = "Publisher";
//The Factory creates the object

$network = Oara_Factory::createInstance($credentials);

I've also added the necessary details on the credentials.ini file:

;------------Amazon (All the newtwork are available)------------

;The user name used in Amazon associates to log in
amazon.user = 'my amazon affiliate email'

;The password used in Amazon associates to log in
amazon.password = 'my amazon affiliate password'

;Network we are going to log in: uk, es, us, ca, de, fr, it, jp, cn.
amazon.network = 'us'

But I'm getting the following error:

Failed to find log in form!

I thought it was just the name of the login form at first:

if (!preg_match('/<form name="signIn".*?<\/form>/is', $page, $form)) {
    die('Failed to find log in form!');
}

Since the name in https://affiliate-program.amazon.com is actually sign_in but when I changed it to that it didn't have any effect.

But the real problem is that the $page variable is actually empty. Is it safe to assume that this library is broken or did I do something wrong with the setup? Can you recommend any other library that can do the same thing or probably point me out to some resources that can help me write my own library for logging into the amazon affiliate website and fetch some reports.

Thanks in advance!

回答1:

I use this library, but I don't use the credentials.ini because I've all the credentials in a database.

So I changed the example/generic.php to add the credentials programmatically:

$email = ...;
$password = ...;
$network = ...;
$networkName = "Amazon";
$networkType = "Publisher";


$credentials = array();

//Path for the cookie located inside the Oara/data/curl folder
$credentials["cookiesDir"] = "example";
$credentials["cookiesSubDir"] = $networkName;
$credentials["cookieName"] = "test";

$credentials["user"] = $email;
$credentials["password"] = $password;
$credentials["network"] = $network;
$credentials['networkName'] = $networkName;
$credentials['type'] = $networkType;

//The Factory creates the object
$network = Oara_Factory::createInstance($credentials);
Oara_Test::testNetwork($network);

And I can login and access to the Amazon data. Maybe since you had written this post, there has been some updates to the library. I can say that now it works.

The result I get is:

Total Number of payments: XX

Number of merchants: XX


importing from 01-08-2013 00:00:00 to 31-08-2013 23:59:59
Number of transactions: XX

Number register on the overview: XX


importing from 01-09-2013 00:00:00 to 30-09-2013 23:59:59
Number of transactions: XX

Number register on the overview: XX


importing from 01-10-2013 00:00:00 to 05-10-2013 23:59:59
Number of transactions: XX

Number register on the overview: XX

Import finished