Monday, April 8, 2013

google api chart tools Visualization

https://developers.google.com/chart/interactive/docs/gallery/areachart

<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("visualization", "1", {packages: ["corechart"]});
        jQuery(document).ready(function () {
            google.setOnLoadCallback(drawGraph);
            function drawGraph() {
                var data = google.visualization.arrayToDataTable([
                    ['Month', 'Pritom', 'Samir', 'Raju', 'Sanjoy', 'Kamol'],
                    ['2004/05', 165,      938,     522,     998,     450],
                    ['2005/06', 135,      1120,    599,     1268,    288],
                    ['2006/07', 157,      1167,    587,     807,     397],
                    ['2007/08', 139,      1110,    615,     968,     215],
                    ['2008/09', 136,      691,     629,     1026,    366]
                ]);

                // Create and draw the visualization.
                var ac = new google.visualization.AreaChart(document.getElementById('visualization'));
                ac.draw(data, {
                    title: 'Monthly Point Distribution',
                    isStacked: true,
                    width: 600,
                    height: 400,
                    vAxis: {title: "Point"},
                    hAxis: {title: "Month"}
                });
            }
        });
    </script>
</head>
<body>
<div id='visualization'></div>
</body>
</html>


And output will be like this:

Sunday, April 7, 2013

Googple api clients scopes for analytics, calender and more

<?php
global $apiConfig;
$apiConfig = array(
    // True if objects should be returned by the service classes.
    // False if associative arrays should be returned (default behavior).
    'use_objects' => false,
  
    // The application_name is included in the User-Agent HTTP header.
    'application_name' => '',

    // OAuth2 Settings, you can get these keys at https://code.google.com/apis/console
    'oauth2_client_id' => '',
    'oauth2_client_secret' => '',
    'oauth2_redirect_uri' => '',

    // The developer key, you get this at https://code.google.com/apis/console
    'developer_key' => '',
  
    // Site name to show in the Google's OAuth 1 authentication screen.
    'site_name' => 'www.example.org',

    // Which Authentication, Storage and HTTP IO classes to use.
    'authClass'    => 'Google_OAuth2',
    'ioClass'      => 'Google_CurlIO',
    'cacheClass'   => 'Google_FileCache',

    // Don't change these unless you're working against a special development or testing environment.
    'basePath' => 'https://www.googleapis.com',

    // IO Class dependent configuration, you only have to configure the values
    // for the class that was configured as the ioClass above
    'ioFileCache_directory'  =>
        (function_exists('sys_get_temp_dir') ?
            sys_get_temp_dir() . '/Google_Client' :
        '/tmp/Google_Client'),

    // Definition of service specific values like scopes, oauth token URLs, etc
    'services' => array(
      'analytics' => array('scope' => 'https://www.googleapis.com/auth/analytics.readonly'),
      'calendar' => array(
          'scope' => array(
              "https://www.googleapis.com/auth/calendar",
              "https://www.googleapis.com/auth/calendar.readonly",
          )
      ),
      'books' => array('scope' => 'https://www.googleapis.com/auth/books'),
      'latitude' => array(
          'scope' => array(
              'https://www.googleapis.com/auth/latitude.all.best',
              'https://www.googleapis.com/auth/latitude.all.city',
          )
      ),
      'moderator' => array('scope' => 'https://www.googleapis.com/auth/moderator'),
      'oauth2' => array(
          'scope' => array(
              'https://www.googleapis.com/auth/userinfo.profile',
              'https://www.googleapis.com/auth/userinfo.email',
          )
      ),
      'plus' => array('scope' => 
        'https://www.googleapis.com/auth/plus.login',
        'https://www.googleapis.com/auth/plus.me',
        "https://www.googleapis.com/auth/userinfo.email",
        "https://www.googleapis.com/auth/userinfo.profile"
       ),
      'siteVerification' => array('scope' => 'https://www.googleapis.com/auth/siteverification'),
      'tasks' => array('scope' => 'https://www.googleapis.com/auth/tasks'),
      'urlshortener' => array('scope' => 'https://www.googleapis.com/auth/urlshortener')
    )
);

Add/modify/delete users to google analytics account


http://support.google.com/analytics/answer/1009702?hl=en

The features described in this article are only available to Analytics account administrators.
In addition to administrators, you can also add users with read-only access to reports. Those users cannot modify Analytics settings, and you can restrict them to specific profiles.
You can add as many users to an account as you wish.
To add a new user:
  1. Click the Admin tab at the top right of any page in Analytics.
  2. Click the account to which you want to add a user.
  3. Click the Users tab.
  4. Click + New User.
  5. Enter the email address for the user's Google Account. Separate multiple addresses by commas or spaces.
  6. Select User.
  7. From the Available profiles list, select the profiles to which the user should have access. If you do not select a profile, those reports are not available to the user.
  8. Click Add to move these profiles to the Selected profiles list.
  9. Click Save. Any users you created can now log in to Analytics using their Google Account email addresses and passwords.

To modify access for an existing user:
  1. Click the Admin tab at the top right of any page in Analytics.
  2. Click the account to which the user belongs.
  3. Click the Users tab.
  4. Click settings for that user.
  5. If you want to promote the user to an administrator, select Administrator.
  6. If you want to make additional profiles available to the user, select those profiles from the Available profiles list, then click Add.
  7. If you want to remove profiles from the user, select those profiles from the Selected profiles list, the click Remove.
  8. Click Save.

To delete a user:
  1. Click the Admin tab at the top right of any page in Analytics.
  2. Click the account to which the user belongs.
  3. Click the Users tab.
  4. Click delete for the user you want to delete.

Add a new account to google analytics

Add a new account

http://support.google.com/analytics/answer/1009694?hl=en 

To sign up for a Google Analytics account, go to http://www.google.com/analytics and click the Sign up now link. Or, if you are already an AdWords user, you can create a new account via Google Analytics under the Tools and Analysis tab on the AdWords interface.
Creating Additional Analytics Accounts
You can create new Google Analytics accounts even if you are an Administrator for another account.
  1. Sign in to your current Google Analytics account at http://www.google.com/analytics.

  2. Click the Admin tab at the top right of the page.

  3. Above the Profiles tab, at the top of the page, click the All Accounts portion of the link (the full link is: All Accounts > the account to which you're logged in).

  4. Click + New Account.

  5. Select whether you want to track a website or app.

  6. Website: Enter the website name and URL.
    App: Enter the name of the app.

  7. Select an industry category.

  8. Under Data Sharing Settings, select the data-sharing options you want.

  9. Under Reporting Time Zone, select your country or territory from the menu, and select the time zone you want to use.

  10. Enter the name you want to use for the account.

  11. Click Get Tracking ID.

Google APIs Console and service account setup

Google php library

https://code.google.com/p/google-api-php-client/wiki/OAuth2

https://docs.google.com/file/d/0B5nZNPW48dpFMTA5OU1SbUNkMW8/edit?usp=sharing

Overview

OAuth 2.0 is an emerging standard for accessing protected resources on the web. The Google APIs and the google-api-php-client library support OAuth 2.0.

Further Reading

Overview

Use OAuth 2.0 to access to protected data through the Google APIs. Google APIs support a variety of flows designed to support different types of client applications. With all of these flows the client application requests an access token that is associated with only your client application and the owner of the protected data being accessed. The access token is also associated with a limited scope that define the kind of data the your client application has access to (for example "Manage your tasks"). An important goal for OAuth 2.0 is to provide secure and convenient access to the protected data, while minimizing the potential impact if an access token is stolen.

Google APIs Console

Before you can use OAuth 2.0, you must register your application using the Google APIs Console.
Visit the Google API Console to generate your developer key, OAuth2 client id, OAuth2 client secret, and register your OAuth2 redirect uri. Copy their values since your will need to input them in your application.
  • From the "Services" screen, activate access to the API you want to use.
  • Click on "API Access" in the left column
  • Click the button labeled "Create an OAuth2 client ID"
  • Give your application a name and click "Next"
  • Select your "Application type"
  • Click "Create client ID"
  • Click "Edit..." for your new client ID
  • Under the callback URL, enter the fully qualified URL for your PHP application (example http://localhost/googleplus/index.php).

Web Application

Now that you've registered your application with the Google APIs Console, you can now create a web application that uses OAuth 2.0. Here is an example demonstrating how to do authentication with OAuth 2.0 in a web application. The full code for this sample is in the repository.
<?php
require_once 'path/to/Google_Client.php';

$client = new Google_Client();
$client->setClientId('insert_your_oauth2_client_id');
$client->setClientSecret('insert_your_oauth2_client_secret');
$client->setRedirectUri('insert_your_oauth2_redirect_uri');
$client->setDeveloperKey('insert_your_developer_key');
If the user has been redirected back to our page with an authorization code, exchange the code for an access token.
if (isset($_GET['code'])) {
  $client->authenticate();
  $_SESSION['token'] = $client->getAccessToken();
  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}

Service Accounts

Service Accounts provide certificate-based authentication for server-to-server interactions. This means, for example, that a request from a web application to Google Cloud Storage can be authenticated via a certificate instead of a shared key. Certificates offer better security properties than shared keys and passwords, largely because they are not human-readable or guessable.
Warning: Very few Google APIs currently support Service Accounts. Service accounts are currently supported by the following Google developer services:
  • Google Cloud Storage
  • Google Prediction API
  • Google URL Shortener
  • Google OAuth 2.0 Authorization Server
  • Google BigQuery
To get started:
  1. Visit https://code.google.com/apis/console
  2. Press the down arrow in the left panel (under the Google apis logo).
  3. Press create.
  4. Name your project "Prediction Test Project".
  5. Press create project.
  6. Now a list of APIs should appear. You want to find "Prediction API" and switch that API to "ON".
  7. Select the API Access tab on the left side.
  8. Press "Create OAuth 2.0 Client" and create your client.
  9. Select Service Account as the application type.
  10. Press Download private key.
Now open the examples /prediction/serviceAccount.php sample application in your editor.
  • Make sure you have a recent version of the Google APIs PHP Client downloaded from here.
  • Replace CLIENT_ID with your newly generated clientId. It should look like:
  • xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
  • Replace SERVICE_ACCOUNT_NAME with the email address. It should look like:
  • xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com
  • Replace KEY_FILE with the path to your private key. Make sure it is saved in a safe place, and readable the sample app.
// Set your client id, service account name, and the path to your private key.
// For more information about obtaining these keys, visit:
// https://developers.google.com/console/help/#service_accounts
const CLIENT_ID = 'insert_your_client_id';
const SERVICE_ACCOUNT_NAME = 'insert_your_service_account_name';
// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
const KEY_FILE = '/super/secret/path/to/key.p12';
// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$client = new Google_Client();
...
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(
  SERVICE_ACCOUNT_NAME,
  array('https://www.googleapis.com/auth/prediction'),
  $key)
);
There is a full sample of using the Prediction API with a Service account.
Learn more about Service accounts from the announcement.


Solving invalid_grant errors

Make sure your server's clock is in sync with NTP.


Here is the URL:
The value which you are referencing is:  54774085
And this is also the value I see in the admin area for "Profile ID"  (54774085)

I had used Service Account for Google Analytics, and get token and get data from google analytics in ruby. It's work for me.
You can try to setup Google Analytics to work with your newly created Service Account:
        -Open Admin section of Google Analytics
        -Click on Users and create a new user in Analytics with the e-mail address provided by the Google API Service Account I had done state above. and i resolve error 403. 

Enable OpenSSL Support for PHP on Windows

Enable OpenSSL Support for PHP on Windows 

As a prerequisite, two libraries must be existing in your Windows system: libeay32.dll and ssleay32.dll. Two ways to achieve this:
  • Install OpenSSL for Windows
  • Or, copy these two files to C:\WINDOWS\system32 folder. They’re shipped with PHP package, you can find them in PHP root folder.
OK, it’s time to open php.ini by using any text editor, and remove the semicolon before the following line:
extension=php_openssl.dll
Done!
http://huang.yunsong.net/2009/windows-php-openssl.html 

Saturday, April 6, 2013

Yii customizing the display of url parameters

Add the following rule to your main.php rules array:
'product/<id:[A-Z0-9]+>'=>'site/product',
 
 
You can then get the value by:
$id = Yii::app()->getRequest()->getQuery('id');

$this->createUrl('product',array('id'=>100));
 
 

<?php $this->widget('zii.widgets.CMenu',array(
	'items'=>array(
		array('label'=>'Product 10', 'url'=>array('/product', 'id' => 20 )),
		array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
		array('label'=>'Contact', 'url'=>array('/site/contact')),
		array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
		array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
	),
)); ?> 
 
 
echo $this->createUrl('post/read',array('id'=>$id))."<BR>";
echo $this->createUrl('post/read',array('id'=>$id, 'title' => "New post title")); 

'post/<id:\d+>/<title>'=>'post/read',
'post/<id:\d+>'=>'post/read'