Wednesday, 21 August 2013

Installing phppgadmin and configuring it with postgresql in linux

phppgadmin can be used for developing application which uses psql for database.

Lets begin :

1.install postgresql  by  $ sudo apt-get install postgresql

2. install phppgadmin by $ sudo apt-get install phppgadmin

3. Create a user for postgresql by $ sudo -u postgres createuser -d -r -P username
then enter password for the user created.

4.make apache acknowledge postgresql as a database server by editing the conf file of apache
$sudo gedit '/etc/apache2/apache2.conf'  
and add this in a new line  at the end                   Include /etc/phppgadmin/apache.conf  

5.Restart apache2 server by  $ sudo /etc/init.d/apache2 restart

6. If localhost/phppgadmin throws up 404  then configure postgresql by
editing the conf file  $ sudo gedit /etc/postgresql/9.1/main/postgresql.conf

and add this at the end of file in a new line           listen_addresses = 'localhost'

7. now edit  pg_hba.conf by $ sudo vi /etc/postgresql/9.1/main/pg_hba.conf

Replace         local all all ident sameuser            with              local   all         all                               md5

That would be it.

you can also access postgres by  $ sudo -u postgres psql username

Saturday, 17 August 2013

PHP on Heroku

Heroku allows you to host your php applications free of cost , until your user base increases . This is hence a good place to host ,if you are testing out your application in the market.

Heroku requires GIT which is version control tool, which allows you to track changes you have made to your code.

Lets begin,

Install GIT

Linux users can try the   $sudo apt get install git


You also need to have a Heroku account ,go here


Then install the heroku toolbelt , its a command line interface to upload codes onto heroku; For this go here.  Linux users can  do so by running

$wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh



login to your heroku account from the terminal by
$ heroku login





Go to the directory/folder where you have developed your php application.
Then run   $ git init


This creates a new subdirectory named .git that contains all of your necessary repository files — a Git repository skeleton


You can add all the content in the directory to the git repository by
$ git add .


Once done , commit it by
$ git commit -m "message"




Then run  $ heroku create  . First time users will be asked to add a key, verify the rsa key, the key for git being  16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48


Push the commited code to heroku by
$ git push heroku master




Then run      $heroku open   



It should open up your php application in the default browser !!!





Note , If you make any changes in your code later on, just commit it by 'git commit'  and push it to heroku by 'git push heroku master'

Monday, 22 April 2013

Facebook app development, php SDK, ' $facebook->getuser returning 0 ' Problem

This has been a stubborn problem;
The problem being the user despite attempt to login by clicking the login url was not able to login, as the permission dialog box never appears to allow the user to approve the permission.

But try opening the login url in a new tab, it works !!.  For some reason the permission dialog box never appears in the same page.

So the work around is provided here.


The framework of login/logout looks like this


$facebook->getuser();

if($user)
{
//user logged in display the content
}


else
{
$url = "https://www.facebook.com/dialog/oauth?"
."client_id=CLIENTID&"
."redirect_uri=http://apps.facebook.com/APPNAMESPACE&"
."scope=COMMA_SEPARATED_PERMISSIONLIST";
echo '
<div>

<script> top.location.href="'.$url.'"</script>

</div>';
}


That's it folks.

Monday, 15 April 2013

Twitter apps tutorial

Twitter has a good set of flexible apis which you can use to develop large set of apps.

To start , register a new app from your twitter account, here .
If you are hosting your app in localhost then in 'website' and 'callback url' fields enter the localhost url , something like http://localhost/twitterapp/ ; In case it doesn't get accepted try replacing localhost with 127.0.0.1 or change browser.

Once your app is registered. Download libraries in the programming language of your choice from here .

Once that is done you can start coding on your app.

(Please note you have to use the consumer key and consumer secret provided here in your app development )

The api offered from twitter allows you to

  • Read Tweets from your timeline.
  • See who you follow, and follow new people.
  • Update your profile.
  • Post Tweets for you.
  • Access your direct messages.

for accessing direct messages, you need to select  'Read, Write and Access direct messages' in application access type , provided in the application register page.


Once the user signs in , your application will receive an Oauth token which can be stored in a local Database so that you can have offline (user) account access.
Also once you are aware of a tweet id or user id, you can get offline/online details of it using several api's.



You need to edit the config.php to mention the consumer and secret keys along with the path to callback.php

And specify the path to the main php code aka index.php in callback.php once the user verification is complete

You can customize the signup page in connect.php




Happy coding.

Thursday, 21 February 2013

Running Facebook apps from localhost

It is possible to develop facebook apps in your localhost be it xampp in windows or LAMP in linux.

Lets make a hello world facebook app  here.

Firstly download a php sdk from here .This allows you to use loads of functions which you needn't worry about defining !!

Paste this in your server (directory) /var/www in LAMP or htdocs in xampp

Now you need to register as a developer and also provide details of your app in facebook , so login to your facebook account and register as developer (look here)


Once you are registered as a developer , go here


Click on create new app, and provide the name of your app, (it has to be unique!)

Then click on continue if your app name is accepted, else try with another name.
After the security check , it allows you to edit the app settings.

 The difference between 'App on facebook' and 'website with facebook login' is that when you select app on facebook , The app runs in a canvas page in facebook itself unlike the other case wherin you login via your facebook account in some other website.

Here inside your /var/www or htdocs you need to create a directory_name folder and paste your codes (.php , .html etc) inside it.

I use something like http://localhost/face/app_name/

'app_name' is a folder inside 'face' , this allows you to have multiple app_name inside face.


Now copy this and save as appname.php inside your directory specified in the Canvas url of facebook app.

The php codes needs you to mention appid ,secret and path to facebook.php (from downloaded sdk)

Run the app in a browser , http://localhost/face/app_name/appname.php.

If it is running you should be able to see your profile pic and other information.


PS:

While developing apps you may need to get permissions on certain user data , for that go to permissions in app settings page.


Enter details in User & Friend Permissions: or  Extended Permissions:


To test these go here



In case you need to install server or create localhost go through this


After these steps if still , the app doesn't  run , check link