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

Saturday, 9 February 2013

Haunted by Couldn't load plugin in youtube ?

Recently the youtube videos were not accessible via google chrome browser.(The chrome browser has inherent shockwave flash player,and dosen't rely on explicit installation of flash player .)

There is a solution to this, you can access the google plugin inventory by typing chrome://plugins/   in chrome browser.(check out other google chrome   tricks )

 Disable the pepperflash player

Enjoy Youtube!! .
 

Chrome : "couldn't load plugin"

Disable pepperflash



 Viola,

 And yes this works for all Operating system (Windows,Linux etc )

Sunday, 3 February 2013

Atmega tutorial

Recently i had to collaborate with a medical industry on development of digital weighing machine.

Lets see .
The first think you need to do is download the avr studio software from here,this will allow you to cross compile your code.And then you would be needing a programmer which can transfer the crosscompiled hex files from your machine to the atmega chip , you may need to develop the programmer , check this. Once these are done you have to get a usb programmer software that can allow you to use your programmer. I use 'Atmel usb programmer' from Robokits India along with Winavr for windows.

To start , go to AVR studio
1.Start a new project


 2.Give project details



3.Choose your device.
4.Programme your code
5.Compile for errors
6.Build your solution

Once these are done go to the workspace where the solution is saved, then look into the Debug directory inside your project, there search for a .hex file.This is the cross compiled hex file which you need to transfer to the device via your programmer

Go to the software used for usb programmer (in my case, Robokits)

1.Choose your device

2.Choose your hex file

That would be all.