Sending a file throught a Post with HTTPBuilder in Grails - facebook

I am developing a Facebook Application an i wanna send a video file from myServer to Facebbok User`s Timeline. This is the page with the explanation http://developers.facebook.com/blog/post/515/#video_upload but its a PHP code.
My app is on Grails, and im looking in HTTBuilder class but can't find a way to do this.
Do someone know how to do it?
If isnt possible to do this with HTTPBuilder, in my app, i am using Spring Social Facebook Plugin on Grais
I found the interface MediaOperations but i dont know how to use this interface and use the method postVideo to upload a Video.
Thanks!

Will try to help a bit. You may use MediaOperations interface for this operation. Spring Social Facebook Plugin configures a service called Facebook for you. You can use it via dependency injection.
Here is a simple code example:
import org.springframework.social.facebook.api.Facebook
class FacebookService {
Facebook facebook
def uploadVideo(String videoFileName, String title, String description) {
try {
def videoResource = new FileSystemResource(videoFileName)
facebook.mediaOperations().postVideo(videoResource, title, description)
return true
}
catch (Exception e) {
log.error("Error to upload video to facebook", e)
return false
}
}
}
The video is loaded from the file in the FS by specified file path/name from videoFileName variable. This means, user need to upload the video first, and code should save it to some file in FS first, then upload. Usually this is the best case, as video files are large. Maybe there is a sense to upload the video to facebook in separate thread and don't give the user to wait.

Related

Change in image urls from Facebook Graph API response [duplicate]

I use the url https://graph.facebook.com/{app_user_id}/picture?width=120&height=120 to show the user picture on my app, but since this morning, it has stopped working on mobile devices.
Now, the same url redirects to https://lookaside.facebook.com/platform/profilepic/?asid={app_user_id}&height=120&width=120. This url works on desktop web, but on mobile it redirects again to https://m.facebook.com/platform/profilepic/?asid={app_user_id}&height=120&width=120 and the mobile web refuses to output the image. If I try to load it in the address bar, it is downloaded instead of showed.
I have searched for any change on the Facebook graph api about this but didn't find anything. Any hint to solve this? Thanks.
This seems to be a bug. Started happening to my app earlier on this morning. Still no fix as of yet.
A few bug reports that have been submitted on Facebook for Developers:
Profile Pictures Can't Load
Graph API Profile picture doesn`t work on mobile
Cross site policy error while accessing graph pictures
I faced the same issue today and I'v found a solution for that and it worked for me.
After login we get below Profile pic URL
http://graph.facebook.com/11111111111/picture?type=large&height=320&width=420
11111111111 is your social id/facebook id
now we need to change this URL in order to display image,
here is the code.
try {
profile_pic = new URL("https://graph.facebook.com/" + id + "/picture?type=large");
Log.i("profile_pic", profile_pic + "");
Picasso.with(getContext()).
load(profile_pic.toString())
.placeholder(R.drawable.img)
.into(imageviewId);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
id is your socialid/facebook id
in short we just need to remove &height=320&width=420 from url.
you can compare both the url:
http://graph.facebook.com/11111111111/picture?type=large&height=320&width=420
https://graph.facebook.com/11111111111/picture?type=large
and yes you need to change http to https as well
Though I didn't find any official announcements, Facebook during last few days changed their api's, now when you request user's public profile the picture url has extra parameters, ext and hash
Calling the url without these params returns 404 error.
Not sure if the change is affecting Page Scope ID's only.
Currently, when you request user's public profile data the url looks like this
https://lookaside.facebook.com/platform/profilepic/?psid=PAGE_SCOPED_ID&height=1024&ext=1522585606&hash=AeThc8c7EQDFgShs
before it was just
https://lookaside.facebook.com/platform/profilepic/?psid=PAGE_SCOPED_ID&height=1024
It seems to me the only known solution currently would be requesting new public profile data and updating your database.
Hope that helps.

Share contract - Deeplink UWP

I share an content of page, like image and text and it's work fine.
But i try ti share link for when someone click, navigate to a my UWP in a page of content shared before.
Like "Click here": this have a link to navigate for my app installed in uwp.
For navigate to my page I need to pass parameters, such as:
((App)(App.Current)).NavigationService.Navigate<MyPage>(Parameters.ToString());
I dont have any idea to do this. :(
someone help me please?
Thanks
If I understand you correctly; you want to supply a link which will open your UWP app and open a "previously shared" page.
To be able to do this you'll need to register to handle uri activation. You'll have to register a protocoll for your app, for example myawesomeapp:.
Then you can pass some additional parameters when someone click the link: myawsomeapp://navto=sharehistory&showitem=2.
Lastly your apps need to handle when it's launched from a uri in OnActivated:
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
// TODO: Handle URI activation
// The received URI is eventArgs.Uri.AbsoluteUri
}
}
You can read the docs here

How to get my own facebook/twitter wall status using CS5.5?

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.

BlackBerry Facebook jar file in eclipse

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).

Access Facebook albums from a flash app

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