A blend of programming and seo

Category — api

How to get listed in google products

What is google products?

Many people don’t know that google has a search engine designed for products called google products. This service can be used to get more traffic to products on your website.

gproduct logo How to get listed in google products

The first step is to signup with google base. Next, You can start adding your products.

There are a few ways to doing this:


1) one at a time

gproduct one How to get listed in google products

This is the easiest way to add a product. Google provides a step-by-step interface for adding individual products. This works well if you only have a couple of products.

2) Data feed

This format makes it easier to update large amounts of products at one time. Your feed file can be in a variety of different formats: text, XML, or shopping.com/shopzilla feeds.

Here is an example feed (all of these fields are required):

<feed>
<g:condition>refurbished</g:condition>
<g:description>test description</g:description>
<g:id>01</g:id>
<g:link>http://www.mysite.com/product1</g:link>
<g:price>10.00</g:price>
<g:title>my new product</g:title>
</feed>

More information about this can be found here.

After your feed is setup, you can schedule when you want google to retrieve it (daily,monthly, or weekly) by clicking “create” under the schedule column. You just need to specify a link to the xml file (on your webserver).

gproduct schedule How to get listed in google products

3) google base data api

This is an XML based api that allows you to add, update, edit, and remove product information from your feed. More information about this can be found here.

July 2, 2009   No Comments

Connecting to authorize.net with php

What is authorize.net?

The Authorize.Net Payment Gateway is a secure Internet bridge between merchant businesses and the credit card and electronic check payment processing networks. We provide merchants with fast, reliable and secure passage for transaction data via a 128-bit Secure Sockets Layer (SSL) Internet Protocol (IP) connection, and manage the complex routing of payment information to the appropriate credit card processors. See a diagram that illustrates a typical Authorize.Net credit card transaction.

The Authorize.Net Payment Gateway is available to merchants seven days a week, 24 hours a day. The payment gateway offers many features and options that can be tailored to specific merchant business models.

Where do I start?

The first thing that you need to do, is signup with a test account. This will allow you to test out transactions to make sure your scripts are interfacing properly with their API. Here is the URL for getting your account:

http://developer.authorize.net/testaccount

API documentation can also be found here:

http://www.authorize.net/support/AIM_guide.pdf

after signing up, you should receive your new account info within 48 hours.

The Code

I have a library available here. It is originally written by Micah Carrick and is under the GPL/GNU public license. I have made some important additions to the main library, which are needed for it to function properly.

Requirements: PHP version 4 and above with the CURL extensions enabled

The following 3 files are contained in the above .zip download:

authorizenet.class.php – main class library for connecting to the authorize.net gateway
demo.php – an example driver file that shows how to use the library file. A test transaction is made to the main gateway.
ca-bundle.crt – main certificate file required by CURL for SSL transactions (windows users can place this in c:\windows\system32)

Important Variables that you need to change

Location: authorizenet.class.php

curl_setopt ($ch, CURLOPT_CAINFO,"c:\\windows\\system32\\ca-bundle.crt");
curl_setopt ($ch,CURLOPT_CAPATH,"c:\\windows\\system32\\ca-bundle.crt");

change the 3rd parameter “c:\\windows\\system32\\ca-bundle.crt” to the location of your CRT file.

Location: authorizenet.class.php

var $gateway_url = "https://test.authorize.net/gateway/transact.dll";

it currently points to the authorize.net gateway for test accounts. If you have an account that is performing real transactions, change this variable to the following value: “”https://secure.authorize.net/gateway/transact.dll”

Location: demo.php

$a->add_field('x_login', 'YOUR_USERID');
$a->add_field('x_password', 'YOUR_PASSWORD');

change x_login to your Login ID (not partner ID)
and x_password to your password

You should have received both of these in an email from authorize.net

June 23, 2009   No Comments

How to use the digg API

digg How to use the digg API

This article will show you how to use the digg API using PHP. I have also written a library in PHP that maps all of the endpoints documented in the API to easily accessible functions (it is also compatible with PHP 4).

What can you do with the digg API?

  • Get all popular stories submitted after January 1, 2007 sorted by promotion date
  • Get the most recent 100 upcoming stories in the topic “Apple”
  • Get the first 20 stories that were promoted on or after December 25, 2005
  • Determine whether a story, identified by its URL, has been submitted to Digg and, if so, get details like the number of Diggs and comments it has received
  • Get the details of a story, identified by its URL on Digg
  • Get all stories submitted today from nytimes.com
  • Get all stories submitted by Kevin Rose (or another Digger)

How it works

Requests are sent to the digg servers through URLS that are described in the API doc (here).

Here is an example:

http://services.digg.com/stories?appkey=http%3A%2F%2Fexample.com

This will return all stories. By default only 10 will be returned at a time (which can be increased to a maximum of 100). Also, you may notice an appkey=XXX argument. This is a unique identifier required by the digg servers. It is recommended to use the urlencoded refereral URL. Other return types are also available, which can make parsing easier depending on the language used.

response types:

  • XML: Easily parsed in many languages on many platforms. It is particularly easy to use in Flash applications.
  • JSON: May be directly eval’d in Javascript, and also can be parsed in many languages.
  • Javascript: Useful as the source of a script tag, it passes JSON response to the Javascript callback function you specify.
  • Serialized PHP: Easily unserialized in PHP to create objects, to which the programmer can attach custom methods. Or the programmer can directly access the response data through the public properties of the objects.

example:

http://services.digg.com/stories?appkey=http%3A%2F%2Fexample.com (will return XML by default)
http://services.digg.com/stories?appkey=http%3A%2F%2Fexample.com&type=json
http://services.digg.com/stories?appkey=http%3A%2F%2Fexample.com&type=php
http://services.digg.com/stories?appkey=http%3A%2F%2Fexample.com&type=javascript

Other basic arguments

    count
    Number of events to retrieve.
    Event count integer
    Default: 10, Maximum: 100.
    offset
    Offset in complete events list.
    Event offset integer.
    Default: 0.

PHP code

The following is a function that will allow you to connect to the digg service and parse the results. It also will automatically generate the appid based on the current location of the script.


function connect($hostname) {
    //this is an ID that is unique to your app.  It is auto-generated, based on the calling URL
    $appid = urlencode(&quot;http://&quot;.$_SERVER[&quot;HTTP_HOST&quot;].$_SERVER[&quot;REQUEST_URI&quot;]);
   
    $host = $hostname.&quot;&amp;appkey=&quot;.$appid;
    echo $host;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_URL,$host);
    curl_setopt ($ch,CURLOPT_USERAGENT,"Test library");
    curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,60);
    $response = curl_exec ( $ch );
    curl_close($ch);
   
    return $response;
}


Download

The digg API toolkit can be downloaded Here

May 6, 2009   7 Comments

Free php library for the google analytics API

Here is a list of other services that google supports using this same protocol:

Application Service name
Calendar Data API cl
Google Base Data API gbase
Blogger Data API blogger
Contacts Data API cp
Documents List Data API writely
Picasa Web Albums Data API lh2
Google Apps Provisioning API apps
Spreadsheets Data API wise
YouTube Data API youtube
Google analytics analytics

Login

Google uses something called the oauth protocol. It’s more secure than basic authentication because it encrypts your datastream. (Twitter currently uses basic authentication for API access, but will also support oath at some point in the future).

From the oath website:

“The Initiative for Open Authentication (OATH) is a collaborative effort of IT industry leaders aimed at providing a reference architecture for universal strong authentication across all users and all devices over all networks. Using open standards, OATH will offer more hardware choices, lower cost of ownership, and allow customers to replace existing disparate and proprietary security systems whose complexity often leads to higher costs.”

I have created a free PHP toolkit for retrieving data from your analytics account.

Example of usage:

<?php
require_once 'googleAPI.class.php';

$gapi = new googleAPI('your username','your password',"a profile");
$reportData = $gapi->viewReport("2009-04-01","2009-04-25","ga:pageviews,ga:visits,ga:newVisits","ga:country,ga:city,ga:date,ga:browserVersion");
?>

You just need to include the analytics library and initialize the object with your username, password, and profile (this is the site name(s) that you see when you first login to your analytics account).

Parameters:

$dateStart: The start date of the report data
$dateEnd: The end date of the report data
$metrics: metric list (multiple metrics need to be separated by commas)
$dimensions: dimensions list (multiple dimensions need to be separated by commas)

You can download it here

Return values

The “viewReport” function returns an array with a list of all the dimensions/metrics that you requested.

Also, a full list of dimensions and metrics can be found here

May 1, 2009   9 Comments