i am currently developing android application...
i want to upload photo to facebook from my application...
i am using this.. but it is to share the link... what i want is to upload photo and message only which user can see whole message in the post.
Please help me!!!
Below is my code:
var appId:String = appId;
var messageTitle:String =title;
var messageUrl:String = link;
var messageDescript:String = message;
var appThumb:String = imageUrl;
var redirectUrl:String = "https://www.facebook.com";
var URLString:String = "https://www.facebook.com/dialog/feed?app_id="+appId+"&link="+messageUrl+
"&description="+messageDescript+"&name="+messageTitle+"&picture="+appThumb+
"&redirect_uri="+redirectUrl;
var req:URLRequest = new URLRequest(URLString);
try{navigateToURL(req,"_blank"); }
catch (e:Error){ trace(">> ERROR <<", e.message); }
U can use a AS3 API for Facebook, it could make your job easier (API AS3 FB)
After FB inizialize and fb login u can use this code
var params:Object = { url:url, message:description, fileName:url_or_filename};
Facebook.api('me/photos', Function_callback , params , 'POST');
But if u want only use Graph URL u need this method https://graph.facebook.com/USER_ID/photos.
You can see more informations and parameters about POST photos HERE
Hope This help
Related
I am having this issue which I hope you can help me solve. Basically I have set up twitter sharing on Corona SDK (using the social plugin) so that players can post their highscores. The game would save a JPEG image and then Twitter loads this inside the message when sharing.
Now the issue is that on iOS, this works perfectly, but on Android devices the image doesn't show in the message body. Can you please help me as I have been banging my head trying to figure this out but have gotten nowhere. Cheers.
Here is my code to take the screenshot:
function takePhoto()
local baseDir = system.DocumentsDirectory
display.save(overlayGroup, "myScreenshot.jpg", baseDir )
print("PIC SAVED")
end
And this these are the options for sharing:
local options = {
service = "twitter",
message = "You got a highscore! ",
listener = tweetCallback,
image = {
baseDir = system.DocumentsDirectory,
filename = "myScreenshot.jpg"
}
}
And these are the code in build.settings
android =
{
versionCode = "1",
googlePlayGamesAppId = "xxxxxxxxxx", --My code is here
usesPermissions =
{
"android.permission.INTERNET",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.ACCESS_WIFI_STATE",
"android.permission.ACCESS_NETWORK_STATE",
},
}
I have prepared an application with image upload. It sends some text and an image.
It's working fine when I add an image and content(text). Unfortunately it's not working when I call the service without an image, see code below,
var params = {
file :$.selectedImageVw.image, //if file is not selected it will send as null
UserId : Ti.App.userID,
postContent : $.postMessage.value
};
var xhr = Titanium.Network.createHTTPClient();
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
progressVw.hide();
// callback("Success");
// alert(this.responseData);
progressVw.hide();
xhr = null;
}
};
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
xhr.setRequestHeader('enctype', 'multipart/form-data');
xhr.setRequestHeader('Content-length', params.length);
xhr.open("POST", "uploadUrl");
xhr.send(params);
I hope someone can help me.
Thanks in advance!!
Try to use a service like http://requestb.in/ to check if the requests made by the client are the issue or the backend you use.
#FokkeZandbergan thanks for your respone,
This issue resolve by very simple modification'
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
changed to
xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");
Now its working with both imags and without images.
It may help to some one . :)
Hey everyone so I was wondering if there is a easy method of doing this or if it can even be done without an ANE Native Extension. I picked up some code from around here and in my Flash CS6 Android AIR Application using AS3 I created two buttons on the stage one for Facebook and the other for Twitter. When the user clicks on the buttons they are redirected to the URL's and are able to post the link that I give in the vars like so:
//Share button event listener
menuEnd.share_Facebook.addEventListener(MouseEvent.CLICK, shareFacebook);
menuEnd.share_Twitter.addEventListener(MouseEvent.CLICK, shareTwitter);
private function shareTwitter(e:MouseEvent):void
{
var varsShare:URLVariables = new URLVariables();
varsShare.u = 'https://play.google.com/store/apps/details?id=air.bunnyRunner';
varsShare.t = 'Jumpy Bunny';
var urlTwitterShare:URLRequest = new URLRequest('http://twitter.com/home?status= Jumpy Bunny by Fitchett Productions: ');
urlTwitterShare.data = varsShare;
urlTwitterShare.method = URLRequestMethod.GET;
navigateToURL(urlTwitterShare, '_blank');
}
private function shareFacebook(evt:MouseEvent):void
{
var varsShare:URLVariables = new URLVariables();
varsShare.u = 'https://play.google.com/store/apps/details?id=air.bunnyRunner';
varsShare.t = 'Jumpy Bunny';
var urlFacebookShare:URLRequest = new URLRequest('http://m.facebook.com/sharer.php');
urlFacebookShare.data = varsShare;
urlFacebookShare.method = URLRequestMethod.GET;
navigateToURL(urlFacebookShare, '_blank');
}
So now I was wondering since I have sharedObject data in my game is there anyway to get that shared.data and display it on facebook when the user clicks the button it shares the data to facebook and they can post their highscore?
Thanks guys any help is appreciated.
Im working on a unity game where you can take a picture and upload this picture to facebook from unity along with some tags and stuff (much like friendsmash). The problem is that i do not have a web-server that i can put the screenshots on, and the Fb.Feeb(picture:) attribute only accepts urls.
I have read that you can use HTTP POST to post the picture to the users images and then use that link in picture:, but i dont know anything about HTTP POST and i couldnt figure out how to do it.
I have also read that you can use FB.API() to somehow do this, but i couldnt figure it out.
Any sample code would be greatly appreciated.
My current code:
private string _path = "file://" + System.IO.Path.Combine(Application.persistentDataPath, "Images/image.png");
void Start ()
{
if (!FB.IsLoggedIn)
FB.Login("email, publish_actions, publish_stream, user_photos", LoginCallback);
StartCamera();
}
private void OnBragClicked()
{
FbDebug.Log("OnBragClicked");
//Post(); <-- dont know how
FB.Feed(
linkCaption: "#hashtag",
picture: "???",
linkName: "Im hashtaging!",
link: "https://apps.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest")
);
}
void TakeSnapshot()
{
_snap = new Texture2D(_webCamTexture.width, _webCamTexture.height);
_snap.SetPixels(_webCamTexture.GetPixels());
_snap.Apply();
//System.IO.File.WriteAllBytes(_path, _snap.EncodeToPNG());
}
The facebook sdk does have a way to make this happen after all. You need to use Fb.API().
This is the way it worked for me:
private void TakeScreenshot()
{
var snap = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
snap.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
snap.Apply();
var screenshot = snap.EncodeToPNG();
var wwwForm = new WWWForm();
wwwForm.AddBinaryData("image", screenshot, "barcrawling.png");
FB.API("me/photos", HttpMethod.POST, LogCallback, wwwForm);
}
In general terms, to add some sort of caption, it's along the lines...
private byte[] postcardAsBytes;
string textMessage = "Play this great game at http://blah.com.";
Dictionary<string, object> d = new Dictionary<string, object>
{
{ "message", textMessage },
{ "picture", postcardAsBytes }
};
Facebook.instance.graphRequest(
"me/photos", HTTPVerb.POST, d, yourCompletionHandler);
// in this example using the prime31 plugin, rather than the fb sdk
The key field seems to be "message". Confusingly, the "dictionary" field documented by FB, seems to just not work, so try "message" at first.
basically, I'm currently building a mobile game using Actionscript 3.0 and AIR (Flash Pro 6). I want to add a facebook share button which the user can post their achievements to their wall.
The post will contains some words and an image.
I didn't know where to start. Can someone please help? thx b4...
This should help:
http://code.google.com/p/facebook-actionscript-api/
There is also documentation here:
http://code.google.com/p/facebook-actionscript-api/downloads/detail?name=GraphAPI_Documentation_1_8_1.zip&can=2&q=
You can use this AS3 code to use FB share button.
fbShareBtn.addEventListener(MouseEvent. CLICK, shareapp)
function shareapp(evt:Event):void
{
var req:URLRequest = new URLRequest();
req.url = "http://www.facebook.com/dialog/feed";
var vars:URLVariables = new URLVariables();
vars.app_id = "xxxxxxxxxxxx"; // your application's id
vars.link = "http://youromainhere";
vars.picture = "http://yourimage";
vars.name = "My Game";
vars.caption = "My Score ";
//vars.description = "My score is " + String(score) + " Try and you!";
vars.redirect_uri = "http://yourdomainhere";
req.data = vars;
req.method = URLRequestMethod.GET;
navigateToURL(req, "_blank");
}