Unity Facebook SDK: post screenshot to wall not working - android

I am using Unity 4.5, the latest facebook sdk 6.0 and I am working on android right now but it should also work on iOS.
I am trying to take a screenshot and upload it to my wall, therefore I use the standard example scene from the facebook sdk.
Everything works fine when I use my private account as a test account, and it also works with the facebook app ID's of older projects (at least 1 year old). But with a normal account (no tester) and a new facebook app it is not working.
Do I have to do a full submission to use the "post an image to the users wall" function or am I doing something wrong?
My facebook app says "This app is public and available to all users" . So I guess it should work right?
I use this for login:
private void CallFBLogin()
{
FB.Login("email, publish_actions", LoginCallback);
}
void LoginCallback(FBResult result)
{
if (result.Error != null)
lastResponse = "Error Response:\n" + result.Error;
else if (!FB.IsLoggedIn)
{
lastResponse = "Login cancelled by Player";
}
else
{
lastResponse = "Login was successful!";
}
}
And this as screenshot method:
private IEnumerator TakeScreenshot()
{
yield return new WaitForEndOfFrame();
var width = Screen.width;
var height = Screen.height;
var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
// Read screen contents into the texture
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] screenshot = tex.EncodeToPNG();
textureTest = tex;
var wwwForm = new WWWForm();
wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
wwwForm.AddField("message", "herp derp. I did a thing! Did I do this right?");
FB.API("me/photos", Facebook.HttpMethod.POST, Callback, wwwForm);
}
Hope someone has a solution.
Thank you!

As per the docs. You need to submit your app for review if you require the publish_actions permission.
Review
If your app requests this permission Facebook will have to
review how your app uses it.
When requesting this permission via App Review, please make sure your
instructions are easily reproducible by our team.

Related

AxSU3D Android Facebook Plugin - "The parameter app_id is required"

I'm using AxSU3D's Android plugin in a Unity project. When I try to use the Facebook Login method, I get an error that says "The parameter app_id is required"
I have posted my code below. I have REPLACED the string "fbAppID" with the actual ID. This is just the sample script that came with the plugin that I am trying to use.
Any help will be appreciated
using UnityEngine;
using System.Collections;
using AxSAndroidPlugin.Core;
using AxSAndroidPlugin.Social.Facebook;
public class FacebookSample : MonoBehaviour {
public string fbAppID = "YOUR_FACEBOOK_APP_ID_HERE";
public GameObject picture;
//Texture2D tex;
void OnGUI () {
if(GUI.Button(GUIControls.GetButtonRect(1), "Init" ))
Facebook.Init(fbAppID);
if(GUI.Button(GUIControls.GetButtonRect(2), "Login" ))
Facebook.Login();
if(GUI.Button(GUIControls.GetButtonRect(3), "IsLoggedIn"))
Facebook.IsLoggedIn();
if(GUI.Button(GUIControls.GetButtonRect(4), "User Info")) {
Facebook.GetUserInfo();
}
if(GUI.Button(GUIControls.GetButtonRect(5), "Friends")) {
Facebook.GetFriendsList();
}
if (GUI.Button (GUIControls.GetButtonRect (6), "Load Profile Picture")) {
Facebook.LoadProfilePicture();
}
if (GUI.Button (GUIControls.GetButtonRect (7), "Get Profile Picture")) {
Texture2D tex = Facebook.GetProfilePicture();
picture.renderer.material.mainTexture = tex;
}
if(GUI.Button(GUIControls.GetButtonRect(8), "Send Request")) {
Facebook.SendRequest("This Plugin Rocks!");
}
if(GUI.Button(GUIControls.GetButtonRect(9), "Post To Timeline")) {
string name = "AxS Android Plugin";
string caption = "AxS Android Plugin for Unity";
string description = "A complete solution to all your Android native needs!";
string link = "http://www.axsu3d.com/";
string pictureLink = "http://www.axsu3d.com/DLs/axsu3dLogo.png";
Facebook.PostToTimeline(name, caption, description, link, pictureLink);
}
//Get the user's likes
if(GUI.Button(GUIControls.GetButtonRect(10), "User Likes")) {
Facebook.GetUserLikes();
}
//Logout of Facebook
if(GUI.Button(GUIControls.GetButtonRect(11), "Logout" ))
Facebook.Logout();
if(GUI.Button(GUIControls.GetButtonRect(12), "Back"))
Application.LoadLevel("CoreSample");
}
}
Firstly, wow. I didn't realize something I helped make would show up on SO.
The solution is quite simple, really. You probably did not use the "Merge Manifest" option.
You can find this option under "Tools/AxSU3D/Android/Merge Manifest". This will show a window where you can put in your Facebook app ID.
The option will create or merge a new AndroidManifest.xml file, which will also contain your Facebook App ID.
Try it out.

facebook android app not set up correctly titanium

I have created an app through facebook developers and added an iOS platform and Android platform. iOS is now working with 3.2.2. Android however is not. My aim is to post a pre defined message onto a user's wall. My code is as follows. When I press my button fbShare(outlined below), I am getting a screen pop up with facebook at the top and a message stating:
App Not Setup: The developers of this app have not set up this app properly for facebook
I added the android platform in the apps settings page and copied the bundleID from my project. I also generated the key hash for both the location of my debug keystore and my actual production keystore. Neither have worked. My code for sharing is as follows:
var fbShare=Ti.UI.createImageView({
image:'/images/fbShare.png',
width:'36dp',
height:'36dp',
left:'5dp'
});
Navbar.add(fbShare);
fbShare.addEventListener("click", function (e){
facebookLogin();
});
var fb;
var facebookLogin = function(){
fb = require('facebook');
fb.appid = 'xxxxxxxxxx';
Ti.API.info('facebook logedin?' + fb.loggedIn);
//login if not logged in
if (!fb.loggedIn) {
fb.permissions = ['publish_stream'];
fb.forceDialogAuth = false;
fb.authorize();
fb.addEventListener('login', function(e) {
if (e.success) {
Ti.API.info("Facebook logged in - stage 1");
postToFacebook();
} else if (e.error) {
alert(e.error + " - stage 1");
} else if (e.cancelled) {
alert("Facebook login cancelled - stage 2");
}
});
}else{
postToFacebook();
}
};
var data = {
link : "www.mylink.com",
name : "my name",
message : "my message",
caption : "my caption",
picture : "myPic.jpg",
description : "My description."
};
var postToFacebook = function(){
Ti.API.info("attempting to post to facebook...please wait");
fb.requestWithGraphPath('me/feed', data,
"POST", function(e) {
if (e.success) {
alert("Shared to facebook successfully!");
fbShare.setEnabled(true);
fbShare.setImage('/images/fbShare.png');
Ti.API.info("Posted to facebook wall!");
}else{
if(e.error){
Ti.API.info("cant post to facebook " + e.error);
}else{
Ti.API.info("something else happened...");
}
alert('Something went wrong with your post but facebook could not confirm what.');
fbShare.setEnabled(true);
fbShare.setImage('/images/fbShare.png');
}
});
};
I've been stuck on this for days, Any help or guidance appreciated
I had a similar issue yesterday. My code was correct but I still get that message. I fixed it by setting "Do you want to make this app and all its live features available to the general public?" to YES under "status and review" in Facebook developer website.
if you have done it already then please make sure your key Hashes are correct. Remember you need a debug key and release key.
if you have done the above steps and sure your key hashes are correct then there
will be some other issue.
I hope this helps.

getting user facebook info in as3 air mobile app

I an developing a mobile app that loges in using Facebook username and pass. i am having runtime errors when trying to retrieve user details. I am using the as3 Facebook api.
ArgumentError: Error #1063: Argument count mismatch on Classes::WebViewLogin/userData(). Expected 0, got 2.
here is my code
public function callInit (){
FacebookMobile.init(APP_ID, onInit);
}
public function onInit(success:Object, fail:Object):void{
if (success){
trace("Already logged in");
}
else{
trace("Not logged in");
addChild(logInBtn);
logInBtn.x = logInBtn.y =200;
logInBtn.addEventListener(TouchEvent.TOUCH_BEGIN, logInbtnPressed);
}
}
private function logInbtnPressed(e:TouchEvent){
trace("-----------log in btn pressed-----------");
removeChild(logInBtn);
webView.stage = stage;
webView.viewPort = new Rectangle(10, 10, (stage.stageWidth -15), (stage.stageHeight - 15));
FacebookMobile.login( onLogin , this.stage, extendedPermissions, webView);
}
public function onLogin(success:Object, fail:Object):void{
trace ("onLogin function called");
if (success){
trace("Logged In\n");
//accessCamera.loggedIn();
getUserData();
addChild(logOutBtn);
logOutBtn.x = logInBtn.y =200;
logOutBtn.addEventListener(TouchEvent.TOUCH_BEGIN, onLogout);
}
else{
trace("Login Failed\n");
logInErr.text = "Error logging in to Facebook";
addChild(logInErr);
logInErr.border = true;
addChild(logInBtn);
logInBtn.x = logInBtn.y =200;
logInBtn.addEventListener(TouchEvent.TOUCH_BEGIN, logInbtnPressed);
}
}
public function getUserData(){
//-----------possible suspect line---------------//
FacebookMobile.api("/me" , userData);
}
public function userData(){
trace ("userdata method");
}
public function onLogout(success:Boolean):void {
removeChild(logOutBtn);
trace("Log out");
}
private function logOutbtnPressed(){
FacebookMobile.logout();
}
I am new to working with facebook and mobile apps and can find very little help with using this api. any help would be greatly appreciated.
edit any help on the problem i am having rather than alternative methods?
If you need something quickly you can buy GoViral from Milkman http://www.milkmangames.com/blog/tools/, they will provide Tutorials and email support for about $50
Maybe a better way will be to use the FreshPlanet ANE here :
https://github.com/freshplanet/ANE-Facebook
It's write especially for mobile so you can use direct connect from the device

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.

Android(AIR/Actionscript) Cant return FB access_token from stageWebView

Im simply trying to get my users access token from FB using stageWebView. When i trace the output from the location change/changing events all i get are google/FB urls, none of which have the token.
Here is my code:
var webView:StageWebView = new StageWebView();
function onChanging(e:LocationChangeEvent):void {
trace(e.location);
e.preventDefault();
webView.loadURL(e.location);
webView.stage = null;
}
function onChange(e:LocationChangeEvent):void {
trace(webView.location);
if(webView.location.indexOf("http://google.com") == 0 && webView.location.indexOf("access_token")!=-1) {
trace("?"+webView.location.substring(webView.location.indexOf("access_token"), webView.location.indexOf("&expires_in")));
webView.stage = null;
}
}
function connectFb() {
webView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, onChanging);
webView.addEventListener(LocationChangeEvent.LOCATION_CHANGE, onChange);
webView.stage = stage;
webView.viewPort = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
webView.loadURL("https://graph.facebook.com/oauth/authorize?client_id=123456789012345&redirect_uri=http://google.com&type=user_agent&display=popup")
}
My Codes output:
https://graph.facebook.com/oauth/authorize?client_id=164534120383085&redirect_uri=http://google.com&type=user_agent&display=popup
https://www.facebook.com/dialog/oauth?client_id=164534120383085&redirect_uri=http%3A%2F%2Fgoogle.com&type=user_agent&display=popup
https://www.facebook.com/dialog/oauth?client_id=164534120383085&redirect_uri=http%3A%2F%2Fgoogle.com&type=user_agent&display=popup
http://google.com/
http://google.com/
http://www.google.com/
http://www.google.com/
I tried every tutorial on the net and even bought a book on AS3 facebook dev & still cant figure this out; Any help would be VERY appreciated since this is a fairly important project to me
Use this where you are Updating UI example Loading Profile photo or Name of User
String acc = session.getAccessToken();
Log.e("Access-Token", acc);
Best of Luck

Categories

Resources