Screenshot image is not showing for Twitter share on Android device - android

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",
},
}

Related

AS3 android camera roll crash and restart

Making an AS3 app for android that uses camera roll to load, select and then use an image.
The cameraroll browser works fine, but when the image is selected, the app crashes - almost every time - as it has worked on a handful of occasions (!?!) We assumed a memory issue and attempted to close all other windows / use smaller photos in the camera roll etc. and try different devices - but cannot recreate success consistently. Cannot find another ANE that works either
It fails at the point where the photo has been selected, and RESTARTS the app...
here's the relevant code, any help appreciated.
public function openGallery():void {
var cameraRoll:CameraRoll = new CameraRoll();
if(CameraRoll.supportsBrowseForImage) {
cameraRoll.addEventListener(MediaEvent.SELECT, imageSelected);
cameraRoll.addEventListener(flash.events.Event.CANCEL, browseCanceled);
cameraRoll.addEventListener(flash.events.ErrorEvent.ERROR, mediaError);
cameraRoll.browseForImage();
}
else { trace( "Image browsing is not supported on this device."); }
}
private function imageSelected(event:MediaEvent):void {
trace("Media selected...");
var imagePromise:MediaPromise = event.data as MediaPromise;
_dataSource = imagePromise.open();
if(imagePromise.isAsync) {
trace("Asynchronous media promise.");
var eventSource:IEventDispatcher = _dataSource as IEventDispatcher;
eventSource.addEventListener(flash.events.Event.COMPLETE, onMediaLoaded);
} else {
trace("Synchronous media promise.");
readMediaData();
}
}
private function onMediaLoaded(event:flash.events.Event):void{
trace("Media load complete");
_mediaBytes = new ByteArray();
_dataSource.readBytes(_mediaBytes);
_tempDir = File.createTempDirectory();
var now:Date = new Date();
var filename:String;
filename = now.fullYear + now.month + now.day+now.hours + now.minutes + now.seconds + ".JPG";
_file = _tempDir.resolvePath(filename);
//writing temporal file to display image
_stream = new FileStream();
_stream.open(_file,FileMode.WRITE);
_stream.writeBytes(_mediaBytes);
_stream.close();
if(_file.exists){
_imageLoader = new Loader();
_imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onMediaLoadedBitmapData);
_imageLoader.loadBytes(_mediaBytes);
}
}
private function onMediaLoadedBitmapData(event:Event):void{
trace("onMediaLoadedBitmapData");
var loaderInfo:LoaderInfo = LoaderInfo(event.target);
_bitmapData = new BitmapData(loaderInfo.width,loaderInfo.height,false,0xFFFFFF);
_bitmapData.draw(loaderInfo.loader);
addPictureToScreen();
}
I had a similar thing happen in Air for iOS but it was related to picking large images. I just checked the dimensions of the chosen image and then used a scalar matrix if they were past a certain point. Sounds like you've thought about this but maybe look further into that?

upload photo to Facebook from flash mobile project using as3

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

How to acces shared object and display on facebook/Twitter URL Link AS3

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.

Upload picture to facebook from unity

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.

AIR Actionscript 3 Adding facebook share button

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");
}

Categories

Resources