i'm trying to learn how to get my own facebook & twitter wall status into flash so that I can export it out and install it in my iPhone.
After reading the facebook and twitter API documentation, I'm still very confussed on how to use them.
I'm very new to this and hope to get a suitable tutorial/sample code for some reference.
Help is appreciated. Thank you.
For Twitter it is easy. Just write the AS3 code to load the Twitter user RSS as XML. After that you will be able to use it.
var myXmlLoader:Loader = new Loader();
myXmlLoader.load(new URLRequest("http://twitter.com/statuses/user_timeline/#twitterUser.rss"));
// just replace "twitterUser" with your twitter user, leave all the rest as is
myXmlLoader.addEventListener(Event.COMPLETE, xmlLoadCompleted);
function xmlLoadComplete(evt){
var myWallData:XML = new XML(evt.target.data);
trace(myWallData); // you will get an RSS XML with the last 20 tweets from your account
}
To get an RSS from your Facebook wall you can use this:
https://www.facebook.com/feeds/page.php?id=23749877160&format=rss20
where 23749877160 is your Facebook account ID
that will give you an rss with your Facebook just as twitter does,
But you need some trick to load it with flash.
Locally you can load it and it works good using the same code to load the twitter,
but on the web your swf wont be able to load, some crossdomain issue.
To fix this what I did is a simple PHP file to load the rss and save a file with the loaded content.
PHP code:
<?php
set_time_limit(300); // this is to set the time limit to execute a code, is that the facebook wall take too long to load
$fbURL = "https://www.facebook.com/feeds/page.php?id=23749877160&format=rss20";
$fileName = "myFileName.xml"; // the name you want to do to your file, the file you will load with flash
$doc = new DOMDocument();
if($doc->load( $fbURL )){
$doc->save($fileName); // saving file in server folder
}else{
echo "error";
}
?>
This is cool but you need to execute the PHP file before intent to load the generated XML. you can use this code to do the trick
AS3 code:
var myPHPLoader:Loader = new Loader();
myPHPLoader.load(new URLRequest("xmlGenerator.xml"));
myPHPLoader.addEventListener(Event.COMPLETE, phpLoaded);
function phpLoaded(evt){
trace("PHP executed");
// do whatever you want
// after the php is executed you can load the fbXml generated normally
}
This works good, but keep in mind that the twitter rss and Facebook RSS, has a call limit per hour (150 call) for twitter, for Facebook I dont know. so if your app reach that limit before complete the hour it will call the empty xml or an error.
dont worry for Facebook in this example you have an PHP that will save the file just if it loads good, if the PHP dont loads the Facebook wall then it wont save the file, so your app will load the old fbXml.
Use the same php to load the twitter rss and save a file to be loaded from your flash app.
What I did is the follow.
PHP Code:
<?php
function savePlainRss($loadURL, $fileName){
set_time_limit(300);
$doc = new DOMDocument();
if($doc->load( $loadURL)){
$doc->save($fileName);
}
}
savePlainRss("https://www.facebook.com/feeds/page.php?id=23749877160&format=rss20", "myFacebookWall.xml");
savePlainRss("http://twitter.com/statuses/user_timeline/#twitterUser.rss", "myTwitterRSS.xml");
?>
This code will save an XML file for twitter rss and Facebook Wall but just if it can load it, if dont it will keep the old file.
Then from flash load the generated XML files.
For me to be sure my app wont reach the call limit and avoid twitter or facebook tag my app as spam, I did a cronjob on my Server to execute the PHP file
each 15 minutes so the calls to twitter and Facebook per hour is just 4, you can find help in google about how to do a cronjob, some hosting and web server have tools to do it.
you can do de calls each 5 minutes if you want more frequently updates or less, but keep in mind that the facebook load can take a long time, up to 300 seconds (5 minutes) dond use less than that to be sure you will have the complete work done.
Thanks for reading.
I hope it helps :)
had alook at it: http://developers.facebook.com/docs/guides/web/ look here for the API.
i dont want to post there code on here...
Also heres seems to have more info:
http://facebook-actionscript-api.googlecode.com/svn/release/current/docs/index.html
this is successful with actionScript, i learned something new
if i got time i will create a basic user status or something and let you know, for now i hoped i pushed you in the right direction.
Related
I am going to create a custom page tab on Facebook and offer a free downloadable PDF with information about my services. Is it possible to track which Facebook users have downloaded the PDF?
An option to look into is authenticating the users individually and receiving their respective Facebook user IDs as a result. You may be interested in reading up on the page tab authentication process referenced here:
Reference: http://developers.facebook.com/docs/authentication/pagetab/
Once you have this user ID, you can track their activity by opening a session containing their user information (to identify them when they download the PDF). For instance, assuming you're using PHP (alongside a CMS):
<?php
if ($current_user->fb_id == 0) {
exit();
} else {
echo $current_user->fb_id;
// do stuff with user here
}
header("Location: http://www.example.com/file.pdf");
// redirect them to the actual file
?>
Hopefully this pseudocode gives you a starting point on your project.
I am developing iPhone application which loads login page of my website. I am able to load my login page using phonegap/childbrowser. I am newbie to JS, Phonegap.
How do my native/phonegap application should handle logout and login event has performed on the webpage? Please guide me how to know user has logged out.
Also is it possible to add support for Push Notification in phonegap/childbrowser application ? How?
So far have seen facebook login-logout questions around but hard to understand and couldnt simulate similar approach.
does your whole app run using the childbrowser? If so why not just have the login log out as piece of your app?
Also if you have to use the childbrowser best bet is to set up a locationchange event and if the location equals a login success page then append some arguments and store those using localstorage.
example -
client_browser.onLocationChange = function(loc){
locationchange(loc);
};
function locationchange(loc){
if(loc.indexOf("http://www.example.com/success?login=true&user=foo") > -1){
var user = loc.match(/user=(.*)$/)[1]; // grab user info
localStorage.setItem('login','true'); // set login as true
localStorage.setItem('user',user); // set username
}
}
that will save to your app locally that the user is logged in and their username, which you can use later if you need to use the childbrowser by passing that in the url you open and on the server side you'll have to look for those arguments.
to log out just open the childbrowser and send a logout argument
www.example.com/logout?user=foo
and in your localStorage
localStorage.setItem('login','false');
Honestly this is kind of a vague question, it would really help to understand why you're wanting to do this in the childBrowser vs your app...
I have a little problem, I don't know how to create the script (with PHP SDK) which check if is the user a fan of my page.
I successfly get the permission for user_likes, but I cant post data to array and after check it.
When I dump this code: $user_likes = $facebook->api('/me/likes'); I'll got all data, but I cant post them to array.
It's amazing what one can find on the internet these days if only he tries to Google his questions...
Here's the first result I got for "facebook is the user a fan":
http://www.masteringapi.com/tutorials/facebook-api-check-if-a-user-is-fan-of-a-facebook-page/20/
It discuss a few options, PHP and JavaScript, Graph API and REST API, just pick your favorite.
FB.api("me/likes/270801249647033", function(response) {
if ( response.data.length == 1 ) {
// Has liked
} else {
// Not liked
}});
Source and download script
From: http://developers.facebook.com/docs/reference/rest/pages.isFan/ (yes, this is deprecated, but it includes the new Graph API way to do things at the top of it. :) )
You can now issue a HTTP GET request to /USER_ID/likes/PAGE_ID (aka /me/likes/PAGE_ID ) to check if a user is a page of a fan.
I know this might sound a very basic question but I am having an issue in using Facebook SDK for Blackberry. I have downloaded the latest one 0.8.25. I have imported them in my eclipse and they are present in the referenced libraries. I have a game app where I want the users to login using their facebook account. Which class contains the code for logging in? Are the jar files implementable or they are just for reference? I have read forums posts where users say that they executed Strawberry program but I can no where find any executable source code. Kindly please let me know how do I create a login page for BlackBerry using its SDK. I did go through another link of Sample Code here!
Let me know which class has login code or how do i use the SDK
At the very basic least, you need to get an instance of the Facebook object and call getCurrentUser(). So, for example:
String[] permissions = new String[] { Facebook.Permissions.ALL_PERMISSIONS };
Facebook fb = Facebook.getInstance(new ApplicationSettings(myNextUrl, myAppId, myAppSecret, permissions));
User fbUser = fb.getCurrentUser();
The code in the library will handle all of the details like getting the user to login to facebook account and accept the requested permissions and so on. You'll want to wrap that all in a try/except to catch FacebookException for error conditions (e.g. user refuses your request).
I want to create a flash Facebook application in which, after pressing a button, the user will be able to browse his/her photo albums and choose a photo. How should i do that? What will be the code under the button to gain authentication from any user using this application?
Thanks.
I am currently writing a facebook application for a university assignment that will allow the user to do everything you can do in facebook, but via the flash player window. You will need a few basic things happening in order to do it.
User log in and authentication - this must be done via Facebook - using OAuth authentication, and meeting all of facebook's security policies
register the application with facebook
Use the Graph API (facebook's developer's toolkit) to get the necessary functions that will communicate with facebook via flash.
In Flash itself you will use a bunch of URLRequest functions to send out to FB for information, then you will need to retrieve that data responses and store them to variables (extracting data with a few lines of code is easy, something like this;
//initialise variables
public var photoURL:String;
var Request:URLRequest = new URLRequest("http://www.whatever the url for the graph api service you are using which is founf from FB");
//that ^^ will send off a request for the url, you then want to use the returned data by registering an event handler like this below
functionName.addEventListener(onComplete, completeHandler);
functionName(event, EVENT)
{
var loader:URLLoader = new URLLoader(Request);
var data:XML = new XMLData(load.loader); //i think this is right but not 100% sure, fiddle with it
//then you want to extract the data that is returned, for example, extracting xml data from a rest request works by hitting data from the xml by specifying a path to the object you want. an example of xml is this <rsp stat="ok"><photos ......more code="morecode"><photo url="url of photo"></photo</photos> so you can hit the url in that example like this;
photoURL = data.photos.photo.#url; //this line will grab the photo url for you, allowing you to dynamically create an array and assign photos to the flash stage according to the url you get
}
this is fairly advanced stuff and I am assuming that you have some decent knowledge on AS3, XML, and the FB API, if you need more help just reply