import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.Resource; import java.io.FileInputStream; import java.util.Properties; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; public class RdfSample { public static Properties properties = new Properties(); public static void main(String[] args) { try { properties.load(new FileInputStream("freebase.properties")); String serviceURL = "https://www.googleapis.com/freebase/v1/rdf"; HttpClient httpclient = new DefaultHttpClient(); String topicId = "/m/02h40lc"; String url = serviceURL + topicId + "?key=" + properties.get("API_KEY"); HttpGet request = new HttpGet(url); HttpResponse httpResponse = httpclient.execute(request); Model model = ModelFactory.createDefaultModel(); model.read(httpResponse.getEntity().getContent(), null, "TURTLE"); Resource topic = model.getResource("http://rdf.freebase.com/ns/" + topicId.substring(1).replace('/','.')); Property labelProperty = model.getProperty("http://www.w3.org/2000/01/rdf-schema#label"); System.out.println(topic.getProperty(labelProperty).getString()); } catch (Exception ex) { ex.printStackTrace(); } } }
Wednesday, October 30, 2013
Saturday, October 26, 2013
Friday, October 25, 2013
App Engine SDK - Google Engine
com.google.apphosting.utils.config.AppEngineConfigException: Invalid configuration
include the following chunk in your appengine-web.xml:
Source:
http://stackoverflow.com/questions/13880528/running-appengine-with-eclipse
include the following chunk in your appengine-web.xml:
<threadsafe>true</threadsafe>
It is mandatory to explicitly set expectations whether your application is designed in a thread-safe way.Source:
http://stackoverflow.com/questions/13880528/running-appengine-with-eclipse
Thursday, October 17, 2013
22 Useful Online Chart & Graph Generators
Have you ever encounter situations where you need to create a
simple yet good-looking chart, graphs or diagrams and all you have is
your browser? Charts are good and effective way to show relationship between entities but sometimes creating one can be pretty challenging especially when your favorite word processing software is not around.
In today’s post, we want to highlight some of the best web services that allow you to create various charts and graphs online on-the-fly. Most of them are easy to use and don’t you even worry about the design. Your output will be as good as what you see in the screen shots below. Full list after jump.
Rich Chart Live
Create enjoyable and captivating Flash Charts from your web browser.
DIY Chart
DIY (Do it yourself) Chart is a Web-based, simple and powerful online tool to create interactive charts and graphs from static or dynamic data which may be generated using any scripting language.
Online Chart Generator
The best online chart and graph generator tool, Generate amazing 3D graphs instantly in few seconds.
Chartle.net
Chartle.net tears down the complexity of online visualizations – offers simplicity, ubiquity and interactivity online chart generator.
ChartGo
ChartGo allows users to create charts online quickly and simply paste your data in the chart data area and hit the create chart button.
Create A Graph
You can really make a detailed graph at Create A Graph and see how it might look, and then print, download, or email what you’ve created.
JS Charts
JS Charts is a JavaScript chart generator that requires little or no coding. JS Charts allows you to easily create charts in different templates like bar charts, pie charts or simple line graphs.
Pie Chart Tool
Pie Chart Tool creates a pie charts based on the data you provide. All you have to do is to type your data and the name of the categories.
Piecolor
Piecolor is a tool that creates pie chart with colors very easily.
Hohli Charts
Hohli Charts lets you dynamically generate charts.
CSS Chart Generator
CSS Chart Generator generates your charts on the fly.
CHARTPART
Google chart API and chart generator tool.
Chart Maker
Generator for the Chart Server API.
Google Chart Tools
The Google Chart Tools enable adding live charts to any web page.
amCharts Visual Editor
This editor allows you to use amCharts as a web service. This means that all you need to do is to configure the chart and paste the generated HTML code to your HTML page.
Pie Chart Maker
This free tool outputs your pie chart as an image that you can save to your computer.
ChartGizmo
With your free account from ChartGizmo you can now create charts for your website, blog and social network profiles.
Onlinecharttool.com
On Onlinecharttool.com you can design and share your own graphs online and for free.
OWTChart Generator
The OWTChart Generator is an on-line tool to be used to produce charts. A GIF image of the chart that you specified will be displayed on the screen.
Highcharts
Highcharts is a charting library written in pure JavaScript, offering an easy way of adding interactive charts to your web site or web application. Highcharts currently supports line, spline, area, areaspline, column, bar, pie and scatter chart types.
iCharts
iCharts is a web-services company that makes data publishing and distribution simple.
Google Chart Generator
Create a Google chart in seconds!
Source:
http://www.hongkiat.com/blog/22-useful-chart-graph-diagram-generators/
In today’s post, we want to highlight some of the best web services that allow you to create various charts and graphs online on-the-fly. Most of them are easy to use and don’t you even worry about the design. Your output will be as good as what you see in the screen shots below. Full list after jump.
Rich Chart Live
Create enjoyable and captivating Flash Charts from your web browser.
DIY Chart
DIY (Do it yourself) Chart is a Web-based, simple and powerful online tool to create interactive charts and graphs from static or dynamic data which may be generated using any scripting language.
Online Chart Generator
The best online chart and graph generator tool, Generate amazing 3D graphs instantly in few seconds.
Chartle.net
Chartle.net tears down the complexity of online visualizations – offers simplicity, ubiquity and interactivity online chart generator.
ChartGo
ChartGo allows users to create charts online quickly and simply paste your data in the chart data area and hit the create chart button.
Create A Graph
You can really make a detailed graph at Create A Graph and see how it might look, and then print, download, or email what you’ve created.
JS Charts
JS Charts is a JavaScript chart generator that requires little or no coding. JS Charts allows you to easily create charts in different templates like bar charts, pie charts or simple line graphs.
Pie Chart Tool
Pie Chart Tool creates a pie charts based on the data you provide. All you have to do is to type your data and the name of the categories.
Piecolor
Piecolor is a tool that creates pie chart with colors very easily.
Hohli Charts
Hohli Charts lets you dynamically generate charts.
CSS Chart Generator
CSS Chart Generator generates your charts on the fly.
CHARTPART
Google chart API and chart generator tool.
Chart Maker
Generator for the Chart Server API.
Google Chart Tools
The Google Chart Tools enable adding live charts to any web page.
amCharts Visual Editor
This editor allows you to use amCharts as a web service. This means that all you need to do is to configure the chart and paste the generated HTML code to your HTML page.
Pie Chart Maker
This free tool outputs your pie chart as an image that you can save to your computer.
ChartGizmo
With your free account from ChartGizmo you can now create charts for your website, blog and social network profiles.
Onlinecharttool.com
On Onlinecharttool.com you can design and share your own graphs online and for free.
OWTChart Generator
The OWTChart Generator is an on-line tool to be used to produce charts. A GIF image of the chart that you specified will be displayed on the screen.
Highcharts
Highcharts is a charting library written in pure JavaScript, offering an easy way of adding interactive charts to your web site or web application. Highcharts currently supports line, spline, area, areaspline, column, bar, pie and scatter chart types.
iCharts
iCharts is a web-services company that makes data publishing and distribution simple.
Google Chart Generator
Create a Google chart in seconds!
Source:
http://www.hongkiat.com/blog/22-useful-chart-graph-diagram-generators/
Wednesday, October 16, 2013
SPARQL in Android
Using ARQoid for Android-based SPARQL Query Execution
I was recently asked about the SPARQL support in Sparql Droid
and whether it could serve as a way for other Android applications to
execute SPARQL queries against remote data sources. It could be used in
this way but there is a simpler alternative I’d like to discuss here.
On the Android platform it is actually quite easy to execute SPARQL
against remote SPARQL endpoints, RDF data and local models. The heavy
lifting is handled by Androjena’s ARQoid, an Android-centric port of HP’s Jena ARQ engine.Both engines (the original and the port) do a great job of simplifying the execution of SPARQL queries and consumption of the resulting data. In this post I’ll go through a simple example of using ARQoid. Note that all the code being shown here is available for download. This post is based specifically on the queryRemoteSparqlEndpoint() method in the com.monead.androjena.demo.arqoid.SparqlExamples class.
Setup
To begin, some environment setup needs to be done in order to have a properly configured Android project ready to use ARQoid.First, obtain the ARQoid JAR and its dependencies. This is easily accomplished using the download page on the ARQoid Wiki and obtaining the latest ARQoid ZIP file. Unzip the downloaded archive. Since I’m discussing an Android application I’d expect that you would have created an Android project and that it contains a libs directory where the JAR files should be placed.
Second, add the JAR files to the classpath for your Android project. I use the ADT plugin for Eclipse to do Android development. So to add the JARs to my project I choose the Project menu item, select Properties, choose Build Path, select the Libraries tab, click the Add JARs… button, navigate to the libs directory, select the JAR files and click OK on the open dialogs.
Third, setup a minimal Android project. The default layout, with a small change to its definition will work fine.
Overview
Now we are ready to write the code that uses ARQoid to access some data. For this first blog entry I’ll focus on a trivial query against a SPARQL endpoint. There would be some small differences if we wanted to query a local model or a remote data set. Those will be covered in follow-on entries.Here is a list of the ARQoid classes we will be using for this initial example:
- com.hp.hpl.jena.query.Query – represents the query being executed
- com.hp.hpl.jena.query.Syntax – represents the query syntaxes supported by ARQoid
- com.hp.hpl.jena.query.QueryFactory – creates a Query instance based on supplied parameters such as the query string and syntax definition
- com.hp.hpl.jena.query.QueryExecution – provides the service to execute the query
- com.hp.hpl.jena.query.QueryExecutionFactory – creates a QueryExecution instance based on supplied parameters such as a Query instance and SPARQL endpoint URI
- com.hp.hpl.jena.query.ResultSet – represents the returned data and metadata associated with the executed query
- com.hp.hpl.jena.query.QuerySolution – represents one row of data within the ResultSet.
The query we will execute is:
SELECT ?dataType ?data WHERE { <http://nasa.dataincubator.org/launch/1961-012> ?dataType ?data. }This query will give us a little information about Vostok 1 launched by the USSR in 1961.
Create the Query instance
We begin by creating the Query instance using the QueryFactory.// Create a Query instance Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);This code assumes that the query given earlier has been assigned to the String variable queryString
Create the QueryExecution instance
We next create a QueryExecution using the QueryExecutionFactory.// This query uses an external SPARQL endpoint for processing // This is the syntax for that type of query QueryExecution qe = QueryExecutionFactory.sparqlService(sparqlEndpointUri, query);This code assumes that the Talis endpoint mentioned above has been assigned to the String variable sparqlEndpointUri.
Execute the query and obtain the ResultSet instance
We are now ready to actually execute the query and obtain the ResultSet instance.// Execute the query and obtain results ResultSet resultSet = qe.execSelect();The resultSet variable now provides us access to the query results.
Retrieve the column names
A useful piece of metadata in the ResultSet instance is the list of column names. These will be based on the information requested in the SELECT clause. ARQoid can return them as a List<String>.// Get the column names (the aliases supplied in the SELECT clause) List<String> columnNames = resultSet.getResultVars();The columnNames List will contain the aliases given in the SELECT clause.
Iterate through the resulting rows
We can now iterate through the resulting rows, asking for each row’s data which is represented as a QuerySolution instance.// Iterate through all resulting rows while (resultSet.hasNext()) { // Get the next result row QuerySolution solution = resultSet.next();The solution variable will contain the current result row’s data.
Obtain the data for a row and column
To actually access the data you can request a specific column name from the QuerySolution instance. However, you need to know whether the data is null, a literal value or a URI. The following code performs the necessary tests and then prints the data to the standard output (in the downloadable code it will be presented on the Android device’s screen).// Data value will be null if optional and not present if (solution.get(var) == null) { System.out.println("{null}"); // Test whether the returned value is a literal value } else if (solution.get(var).isLiteral()) { System.out.println (solution.getLiteral(var).toString()); // Otherwise the returned value is a URI } else { System.out.println(solution.getResource(var).getURI()); }From the code, above, you can see that in order to access the basic data value you use the get(String) method which expects the column name to be passed. This will return null if there is no data associated with this row and column. If there is a value, the method isLiteral() may be called to test whether the data is a literal. If it is not than it will likely be a URI. The URI can be accessed by calling the getResource(String) method, passing the column name, and calling the getURI() method on that value.
Close the QueryExecution instance
The last step is important. The QueryExecution instance should be cleaned up by calling its close() method.// Important - free up resources used running the query qe.close();These are the basic steps you need to carry out in order to execute a SPARQL query against a SPARQL endpoint using ARQoid. Here is a screen shot of the Android emulator executing the example just covered.
Notes
A few other items for completeness. First, remember to add the INTERNET permission to your Android manifest (<uses-permission android:name=”android.permission.INTERNET”/>). Failure to do so will lead to an ARQoid failure when it tries to access the remote endpoint. The stack trace will indicate a failure to access the URI – it won’t mention that there is a permission issue.Also, depending on your query, you may be trying to access a lot of data which could be time consuming and also could cause issues with small memory devices. You may limit the number of rows returned and set a starting row for the results. This allows you to create a sliding window in your application by only pulling a few results and then allowing the user to ask for more. These values are set on the Query instance. Once you have the Query from the QueryFactory you can use these methods.
// Limit the number of results returned // Setting the limit is optional - default is unlimited query.setLimit(10); // Set the starting record for results returned // Setting the limit is optional - default is 1 (and it is 1-based) query.setOffset(11);The limit and offset given above would cause ARQoid to return 10 records, starting with the 11th one found. If there were fewer than 11 results then no records would be returned.
Conclusion
Hopefully if you are trying to use ARQoid this will give you a quick template to leverage the basic features of the engine. In the future I’ll expand on this by adding other data sources as well as using the URIs returned by the query to create a richer result for the user.Remember that you may download the sample code if you want to see the working Android demonstration application described here. Also, you can install Sparql Droid which contains a variety of sample SPARQL queries that use the local model, SPARQL endpoints, RDF data sources as well as demonstrating federated queries.
If you have questions or comments about this topic please add them to this post or send them to me via my contact page.
Source:
http://monead.com/blog/?p=1420
http://answers.semanticweb.com/questions/21688/running-sparql-queries-on-android
http://code.google.com/p/android-sparql/wiki/Deploying_a_SPARQL_Endpoint_and_Populating_the_triple_store
http://oro.open.ac.uk/32335/1/
Tuesday, October 15, 2013
Android Development
Error:
MyProject/ res/
values/ strings.xml
values-es/ strings.xml
values-fr/ strings.xml
The type java.lang.Object cannot be resolved. It is indirectly referenced
from required .class files
Solution:
Make sure that you have a valid JRE or JDK defined in the Java Build
Path of your project. Right-click on your project, select Properties...
and then Java Build Path.
Mount SD Card in Emulator
- Goto the Android Virtual device manager
- click New for create new Vitual device
- Add Name and choose your package
- Under hardware you just click New Button and then pop new Window
- After select SdCard support in drop down list near Property
- finally you have gotten emulator with SDCard support
INSTALL_FAILED_MISSING_SHARED_LIBRARY
error with Google Maps for Android:
- Install Google map APIs. This can be done in Eclispe
Windows/Android SDK and AVD Manager -> Available Packages -> Third
Party Add-ons -> Google Inc. -> Google APIs by Google Inc.,
Android API X
- From command line create new AVD. This can be done by listing
targets (android list targets), then android create avd -n
new_avd_api_233 -t "Google Inc.:Google APIs:X"
- Then create AVD (Android Virtual Device) in Eclipse Windows/Android
SDK and AVD Manager -> New... -> (Name: new_avd_X, Target: Google
APIs (Google Inc.) - API Level X)
IMPORTANT : You must create your AVD with Target as Google APIs (Google Inc.) otherwise it will again failed.
- Create Android Project in Eclipse File/New/Android Project and
select Google APIs Build Target.
- add <uses-library android:name="com.google.android.maps" />
between <application> </application> tags.
- Run Project as Android Application.
Unable to create Android Virtual Device
CPU/ABI says "No system images installed for this target". You need to install a system images.
In the Android SDK Manager check that you have installed "ARM EABI
v7a System Image" (for each Android version from 4.0 and on you have to
install a system image to be able to run a virtual device)
In your case only ARM system image exsits (Android 4.2). If you were
running an older version, Intel has provided System Images (Intel x86
ATOM). You can check on the internet to see the comparison in
performance between both.
In my case (see image below) I haven't installed a System Image for
Android 4.2, whereas I have installed ARM and Intel System Images for
4.1.2
As long as I don't install the 4.2 System Image I would have the same problem as you.
UPDATE : This recent article Speeding Up the Android Emaulator on Intel Architectures explains how to use/install correctly the intel system images to speed up the emulator.
EDIT/FOLLOW UP
What I show in the picture is for Android 4.2, as it was the original question, but is true for every versions of Android.
Of course (as @RedPlanet said), if you are developing for MIPS CPU devices you have to install the "MIPS System Image".
Finally, as @SeanJA said, you have to restart eclipse to see the new installed images. But for me, I always restart a
software which I updated to be sure it takes into account all the modifications, and I assume it is a good practice to do so.
http://stackoverflow.com/questions/13488419/unable-to-create-android-virtual-device
Multi languages string
Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example:MyProject/ res/
values/ strings.xml
values-es/ strings.xml
values-fr/ strings.xml
Monday, October 14, 2013
Thursday, October 10, 2013
Monday, October 7, 2013
Python - Setup and Install Packages A-Z
Setup Python
Download Python Setup: Click to install
Install Modules/Packages
Preparing for easy_install package
- setuptools
cmd\setuptools directory>python setup.py install
If setuptools appears to install correctly, and you can run the
easy_install but need to set PATH VARIABLE includes the appropriate C:\\Python2X\\Scripts directory
- easy_install
do not wish easy_install to actually download anything, you can restrict it from doing so with the --allow-hosts option
cmd>easy_install
Download Python Setup: Click to install
Install Modules/Packages
Preparing for easy_install package
- setuptools
cmd\setuptools directory>python setup.py install
- easy_install
do not wish easy_install to actually download anything, you can restrict it from doing so with the --allow-hosts option
cmd>easy_install
Downloading and Installing a Package
RDFLib is a Python library for working with RDF, a simple yet
powerful language for representing information as graphs.
cmd> easy_install rdflib
Semantic Web Accounting
http://code.google.com/p/3account/wiki/Getting_Started
This page describes a simple installation on Windows. For Unix see following page for detailed install for developers and none Windows OS and description of system architecture.Installing
- Download and Install Java (there is good chance that Java is already installed on your computer.)
- Download 3account base package zip file
- Unzip the file, to any directory you like (for example C:\.) After unzipping, your directory should contain a new 3account directory (for example C:\3account) containing lots of files and sub-directories
Running the system
Use the File Explorer to find the file start.bat in the 3account directory and double click on it; after about a minute, you should see your browser opened on 3account's main page. Note that every time you run start.bat it performs an automatic update of the 3account software.Stopping the system
Close the window opened by clicking on start.bat. You can do this by clicking on the x at the top right cornerUninstalling
Just delete the 3account directoryLoading data
The installation is already loaded with sample data. If you want to load your own data do the following:- Run start.bat as described above (actually you only need its repository which can be started by running sesame.bat)
- Start a windows Command Prompt (Start->All Programs->Accessories->Command Prompt)
- In the command prompt type: cd <3account-directory> (for example cd c:\3account)
- type: Python26\python load3account.py -h you should see help instructions on how to use load3account to load bank statements into the repository. See the following page for more detailed information. You should carefully review if there is any manual property you need to define in order to improve the system results
- After loading data you should stop the system and restart it
Removing data
If you want to remove a file you have previously uploaded, or if you want to remove the sample data, follow these instructions.Address
http://localhost:8000/
Friday, October 4, 2013
Facebook Graph API & OAuth 2.0 & Flash
Facebook Graph API & OAuth 2.0 & Flash (update)
As previously mentioned, facebook released a new Graph API. It is based on OAuth 2.0 protocol (old authorization token also works). While it is fresh thing, there is no much ActionScript stuff around, so I came with FacebookOAuthGraph class. This class is meant to be used as an abstract class, while it contains just the basic authentication algorithm and call method to request data. It stores access token in SharedObject, so next time you came into app, you get connected on background without noticing (no popup etc.). Your token should expire in 24 hours.
Here is the code for the following flex app, to make it work, get latest FacebookOAuthGraph and FacebookOAuthGraphEvent classes.
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
| <? xml version = "1.0" encoding = "utf-8" ?> < mx:Application xmlns:mx = "http://www.adobe.com/2006/mxml" layout = "vertical" applicationComplete = "init()" > < mx:Script > <![CDATA[ import sk.yoz.events.FacebookOAuthGraphEvent; import sk.yoz.net.FacebookOAuthGraph; // facebook Application ID private var clientId:String = "268718683475"; // path to our callback private var redirectURI:String = "http://blog.yoz.sk/examples/FacebookOAuthGraph/callback.html"; // required extended permissions private var scope:String = "publish_stream,user_photos,user_photo_video_tags"; private var facebook:FacebookOAuthGraph = new FacebookOAuthGraph(); [Bindable] private var connected:Boolean; private function init():void { facebook.clientId = clientId; facebook.redirectURI = redirectURI; facebook.scope = scope; facebook.useSecuredPath = true; facebook.addEventListener(FacebookOAuthGraphEvent.AUTHORIZED, authorized); // stage.root.loaderInfo.parameters facebook.autoConnect(parameters); log.text += "checkSavedToken()\n"; } private function connect():void { facebook.connect(); log.text += "connect()\n"; } private function authorized(event:FacebookOAuthGraphEvent):void { connected = true; log.text += "authorized\n"; } private function call(path:String, binary:Boolean):void { var loader:URLLoader = facebook.call(path); loader.dataFormat = binary ? URLLoaderDataFormat.BINARY : URLLoaderDataFormat.TEXT; loader.addEventListener(FacebookOAuthGraphEvent.DATA, callComplete); log.text += "call(" + path + ")\n"; } private function changeStatus(message:String):void { var data:URLVariables = new URLVariables(); data.message = message; var method:String = URLRequestMethod.POST; var loader:URLLoader = facebook.call("me/feed", data, method); loader.addEventListener(FacebookOAuthGraphEvent.DATA, callComplete); log.text += "changeStatus(" + message + ")\n"; } private function callComplete(event:FacebookOAuthGraphEvent):void { log.text += "call completed -> see result\n"; if(event.rawData is ByteArray) { var loader:Loader = new Loader(); loader.loadBytes(event.rawData as ByteArray); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function():void { image.source = loader; }); } else { result.text = event.rawData.toString(); } } ]]> </ mx:Script > < mx:HBox > < mx:Button click = "connect()" label = "connect" /> < mx:Text text = "{connected ? 'connected' : 'not connected'}" /> </ mx:HBox > < mx:HBox visible = "{!connected}" includeInLayout = "{!connected}" > < mx:Text text = "#access_token=121161974560905%7C2..." /> < mx:TextInput id = "hash" /> < mx:Button label = "add hash" click = "facebook.confirmConnection(hash.text)" /> </ mx:HBox > < mx:HBox > < mx:TextInput id = "path" text = "me" /> < mx:Button label = "call" click = "call(path.text, false)" enabled = "{connected}" /> < mx:Spacer width = "20" /> < mx:TextInput id = "path2" text = "me/picture" /> < mx:Button label = "call binary" click = "call(path2.text, true)" enabled = "{connected}" /> </ mx:HBox > < mx:HBox > < mx:TextInput id = "status" text = "testing FacebookOAuthGraph" /> < mx:Button label = "change status" click = "changeStatus(status.text)" enabled = "{connected}" /> </ mx:HBox > < mx:HDividedBox width = "100%" height = "100%" > < mx:TextArea width = "30%" height = "100%" id = "log" /> < mx:TextArea width = "70%" height = "100%" id = "result" /> < mx:Image id = "image" /> </ mx:HDividedBox > </ mx:Application > |
01
02
03
04
05
06
07
08
09
10
| var params = { allowScriptAccess: "sameDomain" }; var attributes = { id: "FacebookOAuthGraphTest" , name: "FacebookOAuthGraphTest" }; swfobject.embedSWF( "FacebookOAuthGraphTest.swf" , "alternative" , "100%" , "100%" , "10.0.0" , "expressInstall.swf" , flashvars, params, attributes); |
callback.html:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> < html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "sk" lang = "sk" dir = "ltr" > < head > < script type = "text/javascript" > <!-- if(window.opener && window.opener.confirmFacebookConnection) { window.opener.confirmFacebookConnection(window.location.hash); self.close(); } //--> </ script > </ head > < body > < p >You may now close this window.</ p > </ body > </ html > |
You get your JSON decoded data via event.data. Just make sure you do not try to decode ByteArray (eg. me/picture)
1
2
3
4
5
| // call("me") private function callComplete(event:FacebookOAuthGraphEvent): void { trace (event.data.name); } |
01
02
03
04
05
06
07
08
09
10
11
| Friends: me/friends News feed: me/home Profile feed (Wall): me/feed Likes: me/likes Movies: me/movies Books: me/books Notes: me/notes Photos: me/photos Videos: me/videos Events: me/events Groups: me/groups |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
| Application ID: 268718683475 App Domain: yoz.sk Website / Site URL: http://blog.yoz.sk/examples/FacebookOAuthGraph/ App on FB / Canvas URL: http://blog.yoz.sk/examples/FacebookOAuthGraph/facebook.php?a=b Page Tab / Page Tab URL: http://blog.yoz.sk/examples/FacebookOAuthGraph/facebook.html? Canvas type: iframe Developer Mode: Off App Type: Native/Desktop Sandbox Mode: Disabled Remove Deprecated APIs: Enabled signed_request for Canvas: Enabled Timezone-less events: Enabled Encrypted Access Token: Enabled ...other Migrations: Disabled |
access_token=268718683475%7C2.w3fjqz80Xi1CdBXt7Ygh6A__.86400.1273158000-1215645368%7CDGv2l2HtTymd6cM6Fy_8k6P_8CQ.
Important update: May 19, 2010: Application is working again. Due to massive support in bug tracker (thanks all for your votes), facebook devs changed secured crossdomain.xml, so it allows unsecured requests. changeStatus() method added into example and some minor changes in FacebookOAuthGraph class (please update).
Here is what happend and why this app was not working for a while:
- May 11, 2010: facebook changed rules, so requests on unsecured graph service (via http://graph.facebook.com…) were limited to just those without access_token parameter. Requets to secured service (https://graph.facebook.com) resulted in security violation due to missing secure=”false” parameter in crossdomain.xml
- May 12, 2010: bug submitted
- May 12, 2010 – May 14, 2010: massive bug voting
- May 14, 2010: Bug confirmed by facebook dev team
- May 19, 2010: Bug fixed, crossdomain file changed
FAQ
Is there a .fla version available?
Yes, there is a simple working Flash CS4 archive available for download (.fla + all sources). The demo connects the facebook application and once connected, it uploads generated picture into photo album.How can I use this class in my iframe canvas page?
Please read article Authorizing Iframe Facebook Applications For Graph APIHow can I make this class do more advanced things and what are the best practices?
Please read article Extending FacebookOAuthGraph Class, where all the most comon extendings are described.When I connect with this app in one browser (firefox), and I run another browser (chrome) I get automatically connected. Why?
Your authorization token is stored in SharedObject, that is OS-user persistent (eg. windows user). No matter what browser you run, all of those reads data from one SharedObject. If you need cookie or session persistent authorization, please extend my class and override methods that use SharedObject.How to add request parameters into my call?
Pass URLVariables object as a second parameter to call() method:
1
2
3
4
| // eg. in order to make this call "me/picture?type=large", do the following: var data:URLVariables = new URLVariables(); data.type = "large" call( "me/picture" , data); |
Why I can not access me/photos?
Facebook has changed rules again. You also need “user_photo_video_tags” permission within your app. I have already added it into my app, so please remove your browser cache, refresh and click connect button again (even if you are connected already). Now it should work.How to upload photo with graph api?
This is a piece of working code from Sean, thnx Sean:
01
02
03
04
05
06
07
08
09
10
| // MultipartURLLoader by Eugene Zatepyakin can be found here: http://bit.ly/9wx4q7 public function uploadImageCall(path: String , ba:ByteArray, message: String , token: String = null ):MultipartURLLoader { var mpLoader:MultipartURLLoader = new MultipartURLLoader(); mpLoader.addVariable( "message" , message); mpLoader.addFile(ba, "image.jpg" , "image" ); loaderAddListeners(mpLoader.loader); mpLoader.load(apiSecuredPath + "/me/photos?access_token=" + token); return mpLoader; } |
Can I make fql calls with this class?
However graph api does not implement fql calls, you can make fql calls using this class. The resulted data are not JSON but XML:
1
2
3
4
5
6
7
8
| var data:URLVariables = new URLVariables(); data.query = "SELECT uid, name FROM user WHERE uid = XXX" ; // insert your uid var loader:URLLoader = facebook.call( "method/fql.query" , data, URLRequestMethod.POST, null , "https://api.facebook.com" ); loader.addEventListener(FacebookOAuthGraphEvent.DATA, fqlComplete); private function fqlComplete(event:FacebookOAuthGraphEvent): void { var xml:XML = new XML(event.rawData); |
Can I post feeds with attachments?
Graph API has not documented attachment functionality for feeds, anyway, you can publish streams with attachments with this class as simple as:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
| var media: Object = {}; media.type = "flash" ; media.swfsrc = "http://zombo.com/inrozxa.swf" ; media.imgsrc = "http://blog.yoz.sk/wp-content/uploads/3d-150x150.jpg" ; media.width = "80" ; media.height = "80" ; media.expanded_width = "120" ; media.expanded_height = "120" ; var attachment: Object = {}; attachment.name = "test name" ; attachment.href = "http://blog.yoz.sk" attachment.description = "test description" ; attachment.caption = "test caption" ; attachment.media = [media]; var data:URLVariables = new URLVariables(); data.message = "test message" ; data.attachment = JSON.encode(attachment); facebook.call( "method/stream.publish" , data, URLRequestMethod.POST, null , "https://api.facebook.com" ); |
How can I develop my app locally when callback only works on the domain?
While callback is not able to push access_token into your app on runtime, I just copy access_token value into my code and publish again:
1
2
3
4
5
6
| if (!parameters.session) parameters.session = JSON.encode({ access_token: String ( "123864964303507%7C2._pSS7WlemeGB9M0RV8Vnuw__.3600.1276246800-1215645368%7C-kYjWPx4MR6DXc5Clcnv5kXX3t4." ) .replace(/\%7C/g, "|" ) }); facebook.autoConnect(parameters); |
Hi Is there a way to implement a “i Like” button with your class?
Sorry, you can not use graph API to like stuff, there is no method for that. Even by testing like request:
01
02
03
04
05
06
07
08
09
10
| href: http://www.facebook.com/pages/*** node_type: page edge_type: like page_id: 12345 action_text now_connected: true nctr[_mod]: connect post_form_id: 123ABF*********** fb_dtsg: TAfAJ post_form_id_source: AsyncRequest |
This example app works with Internet Explorer, but my one results in Error #2032
I can not make it run in my Mac-Safari sonfiguration
It seems there is a bug in Safari on Mac that does not let you open popup via ExternalInterface. You should use navigateToURL() in that case. Credits goes to Beans, thank you. More instructions here.
1
2
3
| var js: String = "return window.navigator.userAgent.indexOf('Safari') > -1);" if (ExternalInterface.call( "function(){" + js + "}" )){ // safari specific code |
Source:
http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/