How to add users with my code

I need to add users with my code without going new users in Admin Setting Section.

I have inserted user information using queries.

$pass = MD5($password);

   $art_qry="insert into piwik_xxxuser(`login`, `password`, `alias`, `email`, `token_auth`, `date_registered`) values('{$username}', '{$pass}', '{$first}', '{$email}', '{$pass}', now())";
 $art_exe=$DB->dosql($art_qry);

 $art_qry1="insert into piwik_xxxaccess(`login`, `idsite`, `access`) values('{$username}', '1', 'view')";
 $art_exe1=$DB->dosql($art_qry1);

The above two queries inserting User data in piwik_xxxuser,piwik_xxxaccess two tables.
But when it automatically user login through my site to piwik , it shows error username and password failed.

I dont know that how to generate user “token_auth” in ‘piwik_xxxuser’ Table.

When Iam Entering user data in users of Admin Setting Section.Its giving authentication.

So Plz respond quikly,

Which method i have to use for User token_auth for giving access to multiple users with my code.

Use the Piwik API. Have a look at the API developer docs. Don’t insert anything into the Piwik database manually.

Hi Beck

Thanks for your reply.I have studied API Developer Docs.But I did’n get solution for this issue.
I need to add multiple users with my code.
Iam getting all the correct except generating User “token auth” In Piwik_XXXuser table
.Iam not inserting manually.
I have already Executed Queries which are above, works fine.

Which Method i have to use for generating User “token_auth” In Piwik_XXXuser table.

can u send the links which will solve my problems.

Plz reply soon.

I spend most of today developing a method to add all of my already established users into the piwik_users table. Beck is correct, try using the API already made to do this.

in a foreach loop of everyone with a siteId already, i told the API to do this:

           $host = 'http://' . $_SERVER['HTTP_HOST'];

           //Adds new user to piwik_users using piwik API
            $httpClient = new Zend_Http_Client($host . '/piwik/index.php');
            $httpClient->setParameterGet(array(
                'module'        => 'API',
                'method'        => 'UsersManager.addUser',
                'format'        => 'PHP',
                'prettyDisplay' => 'true',
                'userLogin'     => $userSettings['username'], //username in the database
                'password'      => $userSettings['password'], //password from db
                'email'         => $dealerSettings['email_address'], //email adress from db
                'alias'         => 'Partner',
                'token_auth'    => 'ee93b283772be8fd9b4a6138ea1f336b' //admin token_auth for permission to do this API
            ));

            $permResponse = $httpClient->request();

Then I did the same to set their permissions using the UsersManager.setUserAccess API.

HI J Stern,

i am using the same function , with my own token_auth and some other values, but its keeps give me the following error.

Fatal error: Class ‘Zend_Http_Client’ not found in H:\wamp\www\bluefree\piwik\test_api.php on line 15.

$host = ‘http://’ . $_SERVER[‘HTTP_HOST’]. “/bluefree”;
$httpClient = new Zend_Http_Client($host . ‘/piwik/index.php’);

my folder structure is as following.

H:\wamp\www\bluefree\piwik\libs\zend

Hi,

I want to use piwik statistics inside my site,

but it giving me login error,

so i use

$row[‘url’] = SITE_URL.“piwikvh/index.php”;
$row[‘fields’] = array(‘module’=>‘Login’,
‘action’=>‘logme’,
‘login’=>‘username’,
‘password’=> md5(‘pswd’),
‘idSite’=> 1012
);

$res = CallUrlUsingCurlArray($row);

and its returning 1,to me.
After that i call iframe, but still ifram saying

“The requested website idSite is not found in the request, or is invalid”

Please provide me the answer.

[size=medium][b]Hi,

I want to use piwik statistics inside my site,

iframe src=“<?php echo SITE_URL;?>piwikvh/index.php?module=Widgetize&action=iframe&moduleToWidgetize=Dashboard&actionToWidgetize=index&idSite=<?php echo $curUserId;?>&period=week&date=yesterday” frameborder=“0” marginheight=“0” marginwidth=“0” width=“100%” height=“800”>Your Browser doesnot support iframe please upgrade your browser.</iframe

but it giving me login error,

so i use

row[‘url’] = SITE_URL.“piwikvh/index.php”;
row[‘fields’] = array(‘module’=>‘Login’,
‘action’=>‘logme’,
‘login’=>‘username’,
‘password’=> md5(‘pswd’),
‘idSite’=> 1012
);

res = CallUrlUsingCurlArray($row);

and its returning 1,to me.
After that i call iframe, but still ifram saying

“The requested website idSite is not found in the request, or is invalid”

Please provide me the answer.[/b][/size]