Android – Facebook SDK AppEventsLogger logEvent doesn't work - java

Googling didn't help me. I'm trying to push data on Facebook dashboard via Facebook app events
My code is:
AppEventsLogger logger = AppEventsLogger.newLogger(this);
logger.activateApp(this, Utility.FACEBOOK_ID);
logger.logEvent(AppEventsConstants.EVENT_NAME_COMPLETED_TUTORIAL);
So, activateApp works fine, but logEvent doesn't.
I've checked app ID and recreated it, but I have the same problem.

Hi you can try add the next row after 'logEvent' method.
logger.flush();
I hope it will be helpful for you.

you need to make sure you have initialized the FB successfully before you calling the logger events:
Facebook.sdkInitilize(Context context);

Related

I have a Problem with Discord4Js MemberJoinEvent

I just started programming a new Discord bot for myself to see what I am able to create. Currently, I'm working on an Autorole feature but I just don't get why the Bot doesn't get triggered by a MemberJoinEvent.
Here is my code:
gateway.getEventDispatcher().on(MemberJoinEvent.class).subscribe(memberJoinEvent -> {
final Member member = memberJoinEvent.getMember();
System.out.println(member.toString());
});
I found the problem! I didnt know that discord changed something in their developer portal. Also I used my old project so I didnt notice it.
You have to manualy enable it in the developer portal, that the bot can access member information. A screenshot of the location to enable the gateway feature
In addition to leguans answer, I also had to request the gateway intents as well!
GatewayDiscordClient gatewayDiscordClient() {
return discordClient()
.gateway()
.setEnabledIntents(IntentSet.all())
.login()
.block();
}
https://docs.discord4j.com/migrating-from-v3-1-to-v3-2/#gateway-intents

Closing an application programmatically with custom error message?

I want to close my Android application with a method, but it should be shown a custom message (which I define for myself).
everything I found yet was "How to close my application" and I got more than 10 ways to close my application but I haven't found a way to set a custom message.
At the moment if my app crashes something like this appears:
[APPNAME] has been stopped
I want something like this
Congratulations! You found a bug, please submit it.
Is there even a way to do that? All methods I found just closed all activities or just forced an unresolveable error.
I don't think you need some code from me, but if you do, tell me.
(Language should be java and javascript/jQuery should be avoided)
You could try making a static stop method:
public static void stop(String message) {
Log.d(message);
System.exit(0);
}

ADAL 4 Android not passing client secret

I'll first say that I'm sure it is just me since people have probably got this to work out of the box without having to edit the ADAL 4 Android Library without editing the source.
When running the sample program and authenticating with a token I get an error from AZURE that it is not passing the client_secret in the message body. I can confirm that this is in fact the case - it is not passing the client_secret.
Although if I edit the OAuth2.java file and change the method buildTokenRequestMessage to something like the following the workflow works perfectly
public String buildTokenRequestMessage(String code) throws UnsupportedEncodingException {
String message = String.format("%s=%s&%s=%s&%s=%s&%s=%s&%s=%s",
AuthenticationConstants.OAuth2.GRANT_TYPE,
StringExtensions.URLFormEncode(AuthenticationConstants.OAuth2.AUTHORIZATION_CODE),
AuthenticationConstants.OAuth2.CODE, StringExtensions.URLFormEncode(code),
AuthenticationConstants.OAuth2.CLIENT_ID,
StringExtensions.URLFormEncode(mRequest.getClientId()),
AuthenticationConstants.OAuth2.REDIRECT_URI,
StringExtensions.URLFormEncode(mRequest.getRedirectUri())
// these are the two lines I've added to make it work
AuthenticationConstants.OAuth2.CLIENT_SECRET,
StringExtensions.URLFormEncode("<MY CLIENT SECRET>")
);
return message;
}
Am I doing something wrong? If not, what is the correct way to access the client secret?
My implementation is straight from the demo application with only changes being setting up the strings to match my endpoints.
Thanks
You need to register your app as a Native application at Azure AD portal. You don't need client secret for native app.

Facebook Android SDK Logout doesn't work

I have a problem, logging out from Facebook with the FacebookSDK (3.7). I already tried lots of possibilities but none seems to work,
when I try with:
fb.logout(ScoreActivity.this);
or with
fb.logout(ScoreActivity.this.getApplicationContext());
or something similar, i get an IllegalArgumentException (but don't know why..)
just a short explanation: "fb" is an object of the type Facebook, and "ScoreActivity" is the activity, where the logout should happen.. Just form Information: The Login is working..
the other method I tried is the following:
I call the following function:
logoutfromfb(ScoreActivity.this.getApplicationContext());
which is defined like this:
public static void logoutfromfb(Context context) {
Session session = Session.getActiveSession();
if (session != null) {
if (!session.isClosed()) {
session.closeAndClearTokenInformation();
//clear your preferences if saved
}
} else {
session = new Session(context);
Session.setActiveSession(session);
session.closeAndClearTokenInformation();
//clear your preferences if saved
}
}
should actually work and I dont even get an error, looking in my LogCat but it's not working, I can press the button how often I want, but nothing happens....
I really hope somebody can help me...
If you need more Infos, just let me know.
I have the same problem it seems that the logout works but since you have the official facebook application still logged in it will authenticate silently again. I'm thinking about creating a "isLogged" var and store it so that when someone logout and restart the app it will not even verify if the user is logged bypassing facebook session verify.
fb.getSession().closeAndClearTokenInformation();
you can use this. it worked for me.

Unexpected error when publishing photo to page

I'm trying to publish a photo to a page using the following:
FacebookClient client = new DefaultFacebookClient(destinationAccessToken);
BinaryAttachment attachment = BinaryAttachment.with(imageName, imageInputStream);
Photo photoResponse = client.publish("/me/photos", Photo.class, attachment);
I'm getting the following response:
{
"error": {
"message":"An unexpected error has occurred. Please retry your request later.",
"type":"OAuthException",
"code":2
}
}
When I use the same code to publish to a user wall it works fine.
I've also tried posting to "/{page id}/photos" with the same result.
The destination access token has the manage_pages, photo_upload, publish_actions, and publish_stream permissions amongst others.
What am I doing wrong here?
UPDATE:
If I publish to a predetermined album using "/{album id}/photos" then it works. Quoting this Facebook developer blog post:
https://graph.facebook.com/USER_ID/photos - The photo will be
published to an album created for your app. We automatically create an
album for your app if it does not already exist. All photos uploaded
this way will then be added to this same album.
So is this behavior broken for pages? Or am I misunderstanding something here?
UPDATE 2:
I found a bug report for this issue, so I'm posting that as an answer.
UPDATE 3:
The bug seems to have been resolved.
I found the Facebook bug report corresponding to this behavior:
http://developers.facebook.com/bugs/355536551171535
So it would seem I'm not doing anything wrong. I guess the temporary workaround would be to check for a predetermined album and create it if necessary, then publish to it. (Note that the user_photos permission is not needed for this workaround, since albums/photos on pages are always public).

Categories

Resources