Sharing on Facebook from Uniy3D - unity3d

Hi ther I am working on a project for Android and I have a button. When the user press the button I want to give him/her the oportunity to share on facebook. This is the code that I am using:
public void ShareOnFacebook()
{
List<string> permission = new List<String>();
permission.Add("publish_actions");
if(!FB.IsLoggedIn)
FB.LogInWithPublishPermissions(permission, null);
FB.FeedShare(
string.Empty,
new Uri("http://linktoga.me"),
"Hello this is the title",
"This is the caption",
"Check out this game",
new Uri("https://i.ytimg.com/vi/NtgtMQwr3Ko/maxresdefault.jpg"),
string.Empty,
callback:ShareCallBack
);
}
void ShareCallBack(IResult result)
{
if (result.Cancelled)
{
Debug.Log("Share Cancelled");
}
else if (!string.IsNullOrEmpty(result.Error))
{
Debug.Log("Error on share!");
}
else if (!string.IsNullOrEmpty(result.RawResult))
{
Debug.Log("Success on share");
}
}
Now the problem is that when I test this on my Android device a Facebook window pops up with a message : "There was a problem. Please try again later".
I am using Facebook SDK 7.4.0

Related

Facebook Login with Unity 5 - Always return me Graph API Error: Bad request

I just start write my first game with unity.
I Created on facebook app - in games category.
I downloaded Facebook idk and added to unity.
I changed app id in Facebook settings.
Now I tried my code:
public class LoginScript : MonoBehaviour {
public string resultstr { get; set; }
public Text LableResult { get; set; }
List<string> perms = new List<string> (){"public_profile", "email", "user_friends"};
// Use this for initialization
void Start () {
LableResult = gameObject.GetComponent<Text> ();
LableResult.text = "Test";
if (!FB.IsInitialized) {
// Initialize the Facebook SDK
FB.Init (InitCallback, OnHideUnity);
} else {
// Already initialized, signal an app activation App Event
FB.ActivateApp ();
}
}
private void InitCallback ()
{
if (FB.IsInitialized) {
// Signal an app activation App Event
FB.ActivateApp ();
// Continue with Facebook SDK
// ...
} else {
Debug.Log ("Failed to Initialize the Facebook SDK");
}
}
private void OnHideUnity (bool isGameShown)
{
if (!isGameShown) {
// Pause the game - we will need to hide
Time.timeScale = 0;
} else {
// Resume the game - we're getting focus again
Time.timeScale = 1;
}
}
// Update is called once per frame
void Update () {
}
private void AuthCallback (ILoginResult result)
{
if (FB.IsLoggedIn) {
// AccessToken class will have session details
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
// Print current access token's User ID
Debug.Log (aToken.UserId);
// Print current access token's granted permissions
foreach (string perm in aToken.Permissions) {
Debug.Log (perm);
}
} else {
Debug.Log ("User cancelled login");
}
}
// On Facebook login button
public void OnFacebook ()
{
FB.LogInWithReadPermissions (perms, AuthCallback);
}
}
But I'm ALWAYS getting in Result:
Graph Api Error: 400 Bad request
And callback_id 2 (sometimes I've seen 3)
Login I try in Mock window with token from facebook.
I tried deploy on iPhone - and game just crashed when I click on login button
Please to close this topic. I fixed it. It was my fail )) (Used app token instead user token )) (Happends)))))
The same thing happened to me!
Remember to check the user token part, which won't be set by default!

How to use Prime31 Google In App Billing Plugin

I just bought "Google In App Billing Plugin for unity3d" by Prime31. I don't understand how to use it in the game that I want to develop.
Can you please show me a code example? I understand I need to use my app key, but I don't know what to do next.
And how to a I make test purchases with this plugin?
Please help as much as you can, because I am really stuck on this subject for quite a while.
This is some of my "purchase maker" object called MoneyTakerScript (inherits from MonoBehaviour):
void Start()
{
string key = "My App Key...";
GoogleIAB.init(key);
var skus = new string[] { "cl.48931", "tp.58932", "mmm.68393" };
GoogleIAB.queryInventory( skus );
TPS = GameObject.Find("TPBtn").GetComponent(typeof(TPScript)) as TPScript;
CLS = GameObject.Find("CLBtn").GetComponent(typeof(CLScript)) as CLScript;
MMM = GameObject.Find("MMBtn").GetComponent(typeof(MMMScript)) as MMMScript;
}
public void Purchase(string ProductId)
{
GoogleIAB.purchaseProduct(ProductId);
}
public void UseProduct(string ProductId)
{
if (ProductId.Contains("cl"))
{
CLS.MakeCL();
}
if (ProductId.Contains("tp"))
{
TPS.MakeTP();
}
if (ProductId.Contains("mmm"))
{
MMM.MakeMMM();
}
GoogleIAB.consumeProduct(ProductId);
}
And this is some of my "purchase listner" object code:
void purchaseSucceededEvent(GooglePurchase purchase)
{
//Debug.Log( "purchaseSucceededEvent: " + purchase );
MoneyScript.UseProduct(purchase.productId);
}
void Start()
{
MoneyScript = GameObject.Find("MoneyTaker").GetComponent(typeof(MoneyTakerScript)) as
MoneyTakerScript;
}
I found the problem and solved it!
This line was missing in my AndroidManifest.Xml for some reason:
<activity android:name="com.prime31.GoogleIABProxyActivity"></activity>
Just added the line and now I have In App Purchase!!

Facebook share in wp8 App

I need to share a message on Facebook in my windows phone App by clicking share button. when click share button , if user has not logged in to Facebook, first we redirect to log in screen and then need to ask permission to publish.
public partial class FacebookLoginPage : PhoneApplicationPage
{
string uriToLaunch ;
// Create a Uri object from a URI string
Uri uri = null;
public FacebookLoginPage()
{
InitializeComponent();
uriToLaunch = #"fbconnect://authorize?client_id={AppID}&
scope=public_profile,publish_actions,read_stream&
redirect_uri=msft-{ProductId}%3a%2f%2fauthorize";
uri = new Uri(uriToLaunch);
this.Loaded += FacebookLoginPage_Loaded;
}
private void FacebookLoginPage_Loaded(object sender, RoutedEventArgs e)
{
DefaultLaunch();
}
// Launch the URI
async void DefaultLaunch()
{
// Launch the URI
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
// URI launched
}
else
{
// URI launch failed
}
}
}
I used above code , but permission screen not appears for publish. Output was as follows.
I followed example and used an AppId, then it works well. I feel that there is special configuration in Facebook App side . Please help me If anyone have idea about it.

Facebook SDK crashes after Login

My code seems to crash on Android with NullPointer exception. But works on ios simulator.
private void CallFBInit()
{
if(!FB.IsLoggedIn){
FB.Init(OnInitComplete, OnHideUnity);
}else{
shareDialog();
}
}
private void OnInitComplete()
{
FB.Login("email,publish_actions",fbLoginCallBack);
}
private void fbLoginCallBack(FBResult result){
shareDialog();
}
#region FB.Feed() example
public bool IncludeFeedProperties = false;
private Dictionary<string, string[]> FeedProperties = new Dictionary<string, string[]>();
private void CallFBFeed(FBResult result)
{
shareDialog();
}
private void shareDialog(){
Dictionary<string, string[]> feedProperties = null;
if (IncludeFeedProperties)
{
feedProperties = FeedProperties;
}
FB.Feed(
toId: FB.UserId,
link: ConfigCS.FeedLink,
linkName: ConfigCS.FeedLinkName,
linkCaption: ConfigCS.FeedLinkCaption,
linkDescription: ConfigCS.FeedLinkDescription,
picture:ConfigCS.FeedPicture,
mediaSource: ConfigCS.FeedMediaSource,
actionName: ConfigCS.FeedActionName,
actionLink: ConfigCS.FeedActionLink,
reference: ConfigCS.FeedReference,
properties: feedProperties,
callback: CallbackForFeed
);
}
#endregion
void CallbackForFeed(FBResult result)
{
if(result.Error!=null){
errorMessage=ConfigCS.fbError+result.Text;
showError=true;
return;
}else{
Debug.Log ("FB Feed error");
}
return;
}
private void OnHideUnity(bool isGameShown)
{
Debug.Log("Is game showing? " + isGameShown);
}
#endregion
I coul'dnt figure out why. When the login dialog is shown, and returns to the app, the app crashes. But if i try again, (since the user is considered logged in), it works without a hiccup. Can somebody see any error in my code?
edit:
To be more precise
1. when user clicks share, fb login dialog opens
2. Once the user successfully logs in, and returns the app, the app crashes with nullpointer exception
I open the app again, and click share (at this point the user is already logged in before the crash) and it works.
I coul'dnt pin point the error since adb log just says NullPointException in facebook.loginActivity.
My initiating function is CallFBInit();
Edit:
One more thing i have noticed is, i have installed facebook sdk 4.3.3 but it shows 4.2.5 in the console
and in the editor
This seems to be a problem with the new 4.3.3 SDK
I have downgraded to 4.2.4 and it works fine.
Is this a known problem?

Not showing FB login screen

I am not able to show facebook login screen, i have downloaded facebook blackberry API https://sourceforge.net/projects/facebook-bb-sdk/,
but it shows me the current user of facebook, if there is no logged in user then it should open log in screen, but its not showing, i am using the below code:
To retrieve the current user (Synchronously):
User user = fb.getCurrentUser();
To retrieve the current user (Asynchronously):
fb.getCurrentUser(new BasicAsyncCallback() {
public void onComplete(com.blackberry.facebook.inf.Object[] objects, final java.lang.Object state) {
user = (User) objects[0];
// do whatever you want
}
public void onException(final Exception e, final java.lang.Object state) {
e.printStackTrace();
// do whatever you want
}
});
my problem is i want the face book login screen, when device does not have any face book user.
You are trying to get the current user asynchronously. Don't do that if you want to see the login screen. Do this instead:
Runnable a = new Runnable(){
public void run(){
ApplicationSettings as = new ApplicationSettings(YOUR_FACEBOOK_NEXT_URL, YOUR_FACEBOOK_APPLICATION_ID, YOUR_FACEBOOK_APPLICATION_SECRET, Facebook.Permissions.ALL_PERMISSIONS);
Facebook fb = Facebook.getInstance(as);
try {
User user = fb.getCurrentUser();
if( user != null){
//do whatever
}
} catch(FacebookException e){
//Crazy happened!
}
}
};
UiApplication.getUiApplication().invokeLater(a);
I think this should solve your problem. Cheers.