I ran into a problem. I am using Unity facebook SDK and FB.API to post on user feed.
The Code I am using is:
if (FB.IsLoggedIn) {
var data = new Dictionary<string, string>() {{"message", "I just scored "+score+" in GameName. Download it now!"}};
FB.API ("/me/feed", HttpMethod.POST,LogCallback, data);
}
void LogCallback (FBResult result) {
if (result.Error != null) {
print ("score submission failed with error= "+result.Error.ToString());
}
else {
print ("score submitted with result= "+result.Text.ToString());
}
}
and the result I am recieving is:
score submission failed with error= java.io.FileNotFoundException: https://graph.facebook.com/me/feed
I searched on the net and found that perhaps it has something to do with
publish_actions
permission. But I am using this permission.
I then went to the see the app on Facebook Developers and went to Status and Review.
There Approved permissions are:
email, public_profile and user_friends
I then tried to add
publish_actions
permission but it showed the error that I am missing icon, long description and privacy policy URL.
It wants to submit app for review. Am I doing everything correct? Do I need to upload android apk for them to review?
Can someone guide me? Thank you
You need to ask for publish_permissions from FB.Login first in order to use the /me/feed. (you'll see a message "this app wants to post on your behalf...")
That said:
Using the graph API to post a message to a user's feed if the user hasn't explicitly clicked a button indicating they want it to happen is known as 'implicit shares' and is discouraged.
Using a message you create in code instead of letting the user type in their own message is known as "pre-filling" and is not allowed by Facebook policies.
You don't need publish_actions if you use the Facebook dialogs instead of the graph API.
Related
I am getting completely stuck on a Facebook login problem in my Unity Android app. I am testing permission flow. When I let the app log in and grant the requested permission, Facebook happily logs me in, but if I deny a permission then it just flat out refuses the login.
This worked two days prior, so that I could log my user in, then check for the denied permissions and re-prompt or tell my app not to ask again.
Now I get the following output when I l try to log in and deny a permission
2021/06/09 12:16:42.012 27863 28095 Info Unity Facebook not logged in {"callback_id":"4","key_hash":"Dd-----------arWY=\n","error":"Unexpected call to LoginManager.onActivityResult"} Accesstoken null
from my debug.log line
Debug.Log(" Facebook not logged in " + result.RawResult + " Accesstoken " + result.AuthenticationToken.ToStringNullOk());
Here is the code involved in the login process. I am a little new to integrating Facebook so it may be that I just missed something obvious, but so far no amount of research has helped me solve this.
public void Login(){
perms = FilterFBPermissions(masterPermissions); //new List<string>(){"public_profile", "email", "user_friends"};
Debug.Log(fbDebugString + " login perms " + perms.Count);
FB.LogInWithReadPermissions(perms, AuthCallback);
}
public void FBLogout() {
FB.LogOut ();
}
/// <summary>
/// After Login.
/// </summary>
private void AuthCallback (ILoginResult result) {
if (FB.IsLoggedIn) {
// Debug.Log (result.RawResult);
FB.API ("me?fields=name,picture.width(400).height(400)", HttpMethod.GET, ProfileDetailsCallback); // Get Facebook Profile Data After Login.
CheckFBPermissions(); //Manie Check the permissions granted by the user via facebook login
} else {
Debug.Log(" Facebook not logged in " + result.RawResult + " Accesstoken " + result.AuthenticationToken.ToStringNullOk());
setCallbackData (null);
Debug.Log("User cancelled login");
}
}
Update
I was on 9.0 Unity sdk. Tried moving to v11 to resolve. No change. Ran code from another project that was working a few days ago, same issue. Starting to think this is a Facebook issue.
Is there a way to get a list of denied permissions without the access token?
Update
I have decided to file a bug report with Facebook since it seems to me to be coming from their side. You can find it at https://developers.facebook.com/support/bugs/4588988171131169/
This issue has resolved itself without me touching my code! Today the login on my app works again but with a different permission window.
May have been fixed by FB dev team suspect this was a temporary issue, just updating for anyone who comes across this thread in future,
Any one else who knows more or could explain better, feel free to jump in.
We all learn together.
After a few days of frustration, I would kindly ask for your help [also apologies as I am very new to FB]. I have an Android app in development, it has a Facebook app id, keys, hashes, etc. I created 4 test users for (obviously) test purposes and made all of these friends and users of the app. The app is set for v2.3 API. I see the increasing restrictions that Facebook is imposing, but I still think that I can do what I need to do ...
On login on the mobile, after the 'two-step' login with simple permission and then ask for more, I ultimately have these permissions:
user_friends
user_posts
manage_pages
publish_pages
publish_actions
public_profile
For a (test) user of the app, that has not yet logged into the app and has therefore not yet granted any permissions, when I query
/v2.3/{user-id}/feed or /v2.3/{user-id}/posts
I get a "200" (non-error) JSON response with no data, from memory its something like this:
{
"data" : [
]
}
which agrees with the documentation as given in FB docs
where it says:
If you attempt to read data from a feed that your app has not been authorized to access, the call will return an empty array. OK, so all that makes sense.
So then I get a list of messages from a friend (test user at this point) and store their message ids, it looks like they are in the form: userid_postid and I can scan the text, great. I use API v2.3 which looks like it will close in July 2017, but it works now.
OK, so now I want to post to the users wall or page or something that FB calls it - is it true that I can't do this anymore? I next tried to post to the comments of the stored user_postid but this fails with:
{HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) Permissions error}
I do think I should have the permission to do this. I do notice that there is no comment widget on the test users posts - is that the problem? Do some posts not have comments at all, or is this a function of test users only? Here is what the posts look like, note there is no comment line shown:
I've come a long way, and can do quite a bit (get posts, user pics, friends that use the app - despite FB's documentation) but am now stuck. Any help or pointers greatly appreciated.
EDIT, forgot the code for the attempted publish to a comment:
params.putString("message", someText);
new GraphRequest(
// version 2.3 will work until July 8, 2017
AccessToken.getCurrentAccessToken(),
"/v2.3/" + mFacebookPostId + "/comments",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
mSends++;
FacebookRequestError err = response.getError();
if (err == null || err.getErrorCode() == 0) {
mSendGood++;
}
tv_status.setText("Sent " + mSends + " posts, " + mSendGood + " good");
}
}
).executeAsync();
Update: am I supposed to get a 'page access token', again the FB docs are not clear?
The answer seems to be a bug with the Facebook Test Users. I was never sure if I could do what I wanted to do as this was a first FB development for me, but started to get suspicious when I saw that Test User's posts do not have comments or like buttons.
But now I am not sure how to test this code, as real users can't use the app in development mode?
I am requesting to get user friends from an Android App that I am developing. As from Facebook Api V2.0 I know that I should get only user friends that have already logged in through my App. However, although I know certain friends of a user have logged In through my App they do not appear in Facebook Request Response when requesting friends of that user. For example I get back 40 friends rather than 50+.
Has anyone experienced this behavior before? I already deleted app from few users to re-authorized it through login but I haven't see any change in the behavior.
Here is the code I'm using:
new Request(ParseFacebookUtils.getSession(),"me/friends", null, null, new Request.Callback(){
#Override
public void onCompleted(Response response) {
if (response == null){
return;
}
else if (response.getError() != null){
response.getError().getException().printStackTrace();
return;
}
GraphMultiResult result = response.getGraphObjectAs(GraphMultiResult.class);
List<GraphObject> fbInList = result.getData();
if (fbInList != null && !fbInList.isEmpty()){
for (GraphObject user : fbInList) {
JSONObject jsonUser = user.getInnerJSONObject(); // The Facebook User
System.out.println("name: " + jsonUser.optString("name"));
}
}
}
}).executeAsync();
I've found what was the problem. When I updated to the latest Facebook SDK, Facebook was returning only 25 friends. I needed to use paging or add a limit to my Friend Request. On previous SDK I didn't need to.
Adding limit:
Bundle params = new Bundle();
params.putString("limit", "50"); // Up to 5000?
friendRequest.setParameters(params);
Relevant Stack Overflow Questions:
Facebook graph API 'friends' request now only returning 25 friends per page? What's going on?
newMyFriendsRequest Facebook returns only 25 friends
Useful Facebook link for paging:
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging
The relevant portion of the doc for you is this
In v2.0 of the API I'm unable to get the full friend list of someone who has logged into my app - is there a way to get the full friend
list?
With Graph API v2.0 and above, calls to /me/friends return only the
friends who also use your app. These friends must have also granted
the user_friends permission. In the cases where you want to let people
tag their friends in stories published by your app, you can use the
Taggable Friends API. If you want to invite people to your app, we
have a number of solutions that depend on the type of app you've built
and the platforms you've built for. Please see our question about
Inviting Friends for more information.
So along with only friends using your app, they should also have authorized user_friends otherwise you wont get their details. Have you done this?
I am trying to setup my app, so the user can login to facebook and i can then upload a post for them, simple.
I have this code
// let the user login
FB.login(function(response) {
if (response.authResponse) {
alert(JSON.stringify(response.authResponse));
// post to facebook
// create our facebook data object
var data = {
access_token: response.authResponse.accessToken,
message: "Upload this post to facebook"
};
// success, now upload the rest of the post, text etc
FB.api('/me/feed', 'post', data, function(response) {
if (!response || response.error) {
alert("There was an error uploading your post to facebook: " + response
.error.message);
} else {
alert("error: " + JSON.stringify(response));
}
});
} else {
alert(
'There was an error logging you in to facebook, or you did not authorize the app to post on your wall'
);
}
}, {
scope: 'publish_stream'
});
Since this is a cordova app, i have this in my device ready event
// initialize facebook
FB.init({
appId: "123456789", // facebook appId
nativeInterface: CDV.FB,
useCachedDialogs: false
});
Now as you can see, i am asking for the permission "publish_stream" which i believe is correct, but i keep getting a message when attempting to post, saying
There was an error uploading your post to facebook (#200). The user hasn't authorizard the application to perform this request
Well i quite clearly have.
I have this on another application that i created nearly a year ago and it all seems to work fine.
One thing i have read about is that "publish_stream" or "publish_actions" is now not available when you login, unless you submit your app for review? is this only for new apps created, as i havent done this with my other app, but it seems to work. This app also shows a message after you login, shown here. I am sure my other app doesnt show this
EDIT:
I have checked my other app and it doesnt show the above message. here is a screenshot
Any help would be appreicated.
publish_stream is deprecated, use publish_actions
before you can use publish_actions for other users, you have to go through a login review process - or the permission will only for for users with a role in your app (Admin/Developer/Tester)
Btw, you are not allowed to prefill the message parameter, it always has to be 100% user generated. And don´t "autopost" right after login (or ever). That´s against the rules too. Check out the platform policy for more information: https://developers.facebook.com/policy/
I want to post a simple status message to a Twitter account that's linked to my app. All users of my app will post to the same Twitter account.
I've registered my app with Twitter (according to the guidance given here: How to post a tweet from an Android app to one specific account?) and I have the necessary ConsumerKey, ConsumerSecret, AccessToken and AccessTokenSecret. I've set the account to Read & Write, and set the REQUEST type to GET.
I'm using Twitter4J and installed the twitter4j-core-3.0.3.jar into my app. The Manifest file has the required "android.permission.INTERNET". This is the code …::
AccessToken a = new AccessToken(AccessToken, AccessTokenSecret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(ConsumerKey, ConsumerSecret);
twitter.setOAuthAccessToken(a);
try
{
twitter.updateStatus("Tweet Test #1");
Log.v(TAG, "Twitter Tweet sent!");
}
catch (TwitterException e)
{
// TODO Auto-generated catch block
Log.e(TAG, "Error sending Tweet:" + e.getMessage());
}
The twitter.updateStatus("xxxxxx") call causes an exception that reports “Received authentication challenge is null” in the logcat.
I assumed I could just post, but it seems Twitter wants something more?
Can anybody offer any advice as to what I'm doing wrong?
Managed to get to the bottom of this in the end!
My particular problem was that I didn't enter a Callback URL in the Twitter Apps setup page. I'm only interested in sending tweets to my app's linked Twitter account and I already have the 4 tokens/secrets, so I don't need to get the user to authorise thier own account via my app. As such, I don't need a Callback URL.
Unfortunately, the Twitter apps page lets you leave that field blank when you request the tokens/secret, and they don't make it clear that the Callback URL is a required field. If you don't need it, you can put absolutely anything you like in there; But if you leave it blank, Twitter won't let you tweet from your app! Setting the access type to "Read & Write" is good enough just to update status, but set it to "Read, Write & Direct Messages" if you want to do more.
Some tutorials say you should set the app type to "Browser" (instead of "Desktop"), but that option seems to have disappeared from the Twitter apps page, so I guess that's no longer important.
I managed to find some very good tutorials about tweeting from an Android app (here, here and, in particular, here) which make it clear that the Callback URL is a requirement, and go on to explain very clearly how to get it to work.
Have you checked to make sure there aren't any extra whitespaces in your Twitter4J configuration file? Double-check each of your consumer.. and access.. fields just in case.