Software Technology Tips

Facebook integration on cross-platform mobile app using Titanium.
The following code is tested with iPhone,iPod and Android.
 
Let say we have a view.
Onclick of that view a window will appear to make post on Facebook.
 
Ti.Facebook.appid = 'Your_Application_Id';          
// We will get this ID, when we will regiter this app on facebook
       
Ti.Facebook.permissions = ['publish_stream']; // Give the permission
 
//Code for sharing image/video        
var data =
{
    link         : "link for that image/video",
    name         : "name if want to specify any",
    caption      : "",
    picture      : "thumbnail link",
    description  : "Description"
};
 
// logged in
Ti.Facebook.addEventListener('login', function(e)
{
   if (Ti.Facebook.loggedIn)
   {
                
     Ti.API.info('Logged In');                
     // To post data
    Titanium.Facebook.dialog("feed", data, function(e)
    {
      if (e.success) {
        //alert("Success!  From FB: " + e.result);
       }
       else
       {
        if (e.error)
        {
          alert(e.error);
        } else if (e.cancelled)
        {
          alert('Cancelled');
        } else {
               alert("Unkown result");
        }
       }
   });
                
   }
     else if (e.error) {
      alert(e.error);
     }
      else if (e.cancelled) {
       alert("Cancelled");
      }
        });
 
    //If the user is not loged in
        if (! Ti.Facebook.loggedIn) {
            Ti.Facebook.authorize();            
        }
        
   //After Logged in
        if(Ti.Facebook.loggedIn){
   Titanium.Facebook.dialog("feed", data, function(e) {
    if (e.success) {
        //alert("Success!  From FB: " + e.result);
    }
      else
      {
        if (e.error) {
                  alert(e.error);
        } else if (e.cancelled) {
               alert('Cancelled');
        } else {
               alert("Unkown result");
        }
      }
   });
}


Related Tags:

Titanium, Cross Platform, IPhone, Android, Facebook integration

Author: Raju Mahato

Titanium

Let us Connect!

iso 9001 QA25 Red Herring STPI D&B Fastest Growing SME 2013 Award zinnov Nasscom

copyright (c) Mindfire Solutions 2007-2014. Login