Using the beta 3.0 SDK on Android, I'm opening a Facebook Session with a simple session.openForRead() call with basic permissions (email).
As soon as I want to publish a message on a user's wall I'm re-authorizing the session with session.reauthorizeForPublish() including the new publish permissions (publish_actions) in the ReauthorizeRequest object.
As soon as the last request succeeded, a call to session.getPermissions() only returns the last requested permissions (publish_actions), but loses all of the previous read permissions (email).
The documentation of ReauthorizeRequest's parameter permission clearly states "additional permissions to request", so I'm currently not quite sure why the session loses all the other permissions after a request?
Many thanks,
Alex
Alex, sorry you are running into this. This is a bug in the SDK that we are working on fixing prior to the final release. In the meantime, there are a couple of workaround approaches you could try.
While the Session object's notion of its permissions is out of sync with the Facebook service, the access token associated with the Session still has those permissions and can still be used to make Graph API calls requiring any of the permissions it has been granted (unless the user has subsequently revoked any of them, of course). So if your application logic allows you to disregard the results of the Session.getPermissions() call (for instance, if your UI flow implies the user must have already granted a certain permission prior to reaching a certain step in the flow, so you can assume it is present), you can go ahead and make Graph API calls that require those permissions regardless of what getPermissions says -- real truth about what permissions are associated with the token lives in the service, not in the Session object.
If your app logic is such that you need to check whether a certain permission has been granted, unfortunately right now you may need to keep track of the permissions separately,
perhaps by declaring an ArrayList<String> somewhere that you append the new permissions to, perhaps in your Session.StatusCallback whenever the session is opened, and clear it whenever the session is closed. (You could also make a call to "me/permissions" each time the state transitions to OPENED_TOKEN_UPDATED and store the results.) This should be considered only a temporary workaround until the real fix is available. Hope this helps.
Related
I upgraded firebase analytics to v18.0.2 and after that, I cannot get anymore app instance id using getAppInstanceId, I started to get null.
According docs for getAppInstanceId
Retrieves the app instance id from the service, or null if FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE has been set to FirebaseAnalytics.ConsentStatus.DENIED.
I see in my logs that ANALYTICS_STORAGE is denied.
Analytics storage consent denied; will not get app instance id
I don't understand why is denied provided setConsent method states that all types are granted by default
Sets the applicable end user consent state (e.g., for device identifiers) for this app on this device. Use the consent map to specify individual consent type values. Settings are persisted across app sessions. By default consent types are set to "granted".
I'm not sure how I'm supposed to deal with this new consent feature but provided there is a public setter (setConsent) I tried to manually set the granted status. (Xamarin C# code, not native but it shouldn't be relevant)
_firebaseAnalytics.SetConsent(new Dictionary<ConsentType, ConsentStatus>
{
{ ConsentType.AnalyticsStorage, ConsentStatus.Granted }
});
It didn't make a difference.
How should I deal with this new consent feature so I can get the app instance id?
This is the list of Firebase and Google Play references (Again, it's a Xamarin app so I have Xamarin references, hopefully the translation to native world is obvious)
As mentioned under Manage consent settings, the default values for Ads/Analytics storage are determined by google_analytics_default_allow_ad_storage and google_analytics_default_allow_analytics_storage in the app's AndroidManifest.xml file.
So if those values are set to true then this would also result in a null value.
Assuming none of this applies, I see that 18.0.3 "Fixed a bug in the Google Analytics Consent API". So maybe that's the root cause.
NOTE FOR IOS: iOS 14 added a new consent dialog for access to the identifier (IDFA) and if this is declined by the user, it will not be available no matter what has been set by the developer. You can read more here.
Once again I require your help stackoverflowers!
I've been working on a SDK and now need to verify that the user granted the permissions for stuff like location or file writing.
Verifying is fine, but I think I should ask for the permission if it's needed. The thing is, I have absolutely no access to any activities. I might use the appContext to check for the permissions, but I can't listen to onRequestPermissionsResult like this.
Is there a clever way to ask for permission from my side or should I ask the developers using my SDK to ask the permissions timely so I can use the feature I (and they) need later on?
Thanks for the help!
Personally I'd prefer SDKs to let me as the developer handle when to ask permissions as I may need to give the user some warning, handle it in advance or do other things before prompting them.
If you look at SDKs like Google Play Location services it leaves the handling of the location permissions to the developer and simply adds a warning to the calls that could fail by stating it may throw a SecurityException.
There is also an annotation they use called android.support.annotation.RequiresPermission which you could use to help users of your SDK. Using this annotation will give you the above mentioned Exception warning / error.
Example from official documentation:
#RequiresPermission(anyOf = {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION})
public abstract Location getLastKnownLocation(String provider);
And as result
I think that you have to declare permissions into documentation and delegate permission-trouble to your sdk users, because library may be part of Model and it mustn't manipulate with UI (permission dialogs)
You can't call permission dialog without activity
I have two applications -
First - is a Facebook app.
Second - is an app which sends a Broadcast to the first app.
For the First app I have asked the Permissions -
basic_info, email, user_photos, publish_actions
Now, the Second app triggers a BroadcastReceiver in the First app such that the first application is called and it tries to Publish a feed.
However, in the First app the call for getOpenSession().getPermissions() returns an empty List. Hence, I am getting the exception - (The reason might be something different too, I am not sure).
java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that has a pending request.
Since I have asked specifically for these Permissions, why does the call for getPermissions() return an empty array? Am I missing something?
Apart from this what can be the other reasons for the exception?
Turns out, I wasn't passing the proper Permissions when making a Request. We set the Permissions like this -
request = new Session.OpenRequest(mActivity);
request.setDefaultAudience(...);
request.setLoginBehavior(...);
request.setPermissions(permission); // <-- This is where we need to specify the permissions.
session.openForPublish(request);
I do not know whether this is the proper solution, but it seems to work for me.
I'm studying on an android app with using facebook api. I have two activity, first one is to select friends and second one is to send somethings friends wall . I'm getting permission in first activiy but second activity is also requires permission . How can I make first permission in second activity , too .
Is it suitable doing facebook object static?
Permissions are associated with a particular Facebook App (you pass the App ID and App Key to the Android Facebook SDK). Hence, if you use the same Facebook App details in both activities, they both will be having the same permissions.
Peace be upon you,
Acquiring friends' info requires curtain permissions. e.g.
session.requestNewReadPermissions(new NewPermissionsRequest(FacebookLogin.this, Arrays.asList("friends_birthday", ...)));
However, publishing requires different permissions. e.g.
session.requestNewPublishPermissions(new NewPermissionsRequest(FacebookLogin.this, Arrays.asList("publish_actions")));
I recommend that you ask for permissions on need basis. e.g. by adding permission request command in the implementation of a Button.
I'm adding licensing to my app, under allow(), I start the activity. Under dontAllow, I display a dialog saying, not licensed, go to market. Under applicationError, I'm not sure.
I don't want my app to be inaccessible because of an error in code but if I start my activity there, then licensing could just be bypassed if data access is not available. How is everybody handling this?
LVL caches last successful license check status and calls allow() method even if there's no internet connection. But after several tries or after certain time it starts treating license as expired one and calls dontAllow(). Validity period and retries count comes from Android Market, so these values aren't hardcoded in LVL. You can get additional informatoin here: http://developer.android.com/guide/publishing/licensing.html#extras