Set facebook application locale based on user's facebook language settings - facebook

So if i am French and browse facebook in French, is it possible for an application to change its locale or language settings based on that of the user? In other words, if i open the facebook app, i would like to see the app content in French. Similarly for any other language. How can this be done?
P.S. I am using the old REST api

Ok a couple of ways to do this:
1) Check for locale in facebook params when the app loads, in particular the "fb_sig_locale" parameter
2) Use fql on user table like so:
select locale from user where uid = '1100100101'

setup a before_filter like this (I'm assuming You're using I18n to store the current locale) :
if request_comes_from_facebook?
# e.g. "fb_sig_locale"=>"en_US" or "fb_sig_locale"=>"de_DE"
if fb_locale = params[:fb_sig_locale]
I18n.locale = fb_locale.sub('_', '-')
else
logger.info ":fb_sig_locale parameter not found in request"
end
end

Related

App to open in Spanish when participant clicks on Spanish Website in iOS

I have a project and this project support two languages English and Spanish.
If the user has Spanish languages selected phone, the app opens Spanish. The same cycle works for English also.
Second, We have a website and this website provides Spanish and English support. User can register ( Sign Up ) or login (Sign In)
from English site or Spanish site.
My question, As a User if I choose to register via the Spanish site, I should be taken to the app in Spanish and not English.
How can I do this? Universal Link or Deep Link. Is there anyone build this cycle previously?
You cannot change the device's language from within an app.
A solution for your use case could be to manually handle localization in your project: instead of relying on NSLocalizedString you'd have to use your own function for providing the localization for a given string/key. In the "normal" usage scenario you'd use the preferred language of the system; when opening the app via a link you'd add the language as URL parameter and use that language for the app session. (Note that this will not work with Storyboard or Info.plist localizations, only with texts you explicitly set in code).
Use Branch iOS SDK for deep linking so that you can ensure that a user receives the language even when they don't have the app installed before hand. In your links you should be able to set a field language to english, epanish, etc. When ever a user opens your application you can just pull that information out of the Branch callback like so.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// listener for Branch Deep Link data
Branch.getInstance().initSession(launchOptions: launchOptions) { (params, error) in
// do stuff with deep link data (nav to page, display content, etc)
print(params as? [String: AnyObject] ?? {})
let language = params?['language']
//Store this in their NSUserDefaults
let defaults = UserDefaults.standard.set(language, forKey: "language")
}
return true
}
The information in your UserDefaults will persist until the user deletes the app and reinstalls it.
let language = UserDefaults.standard.string(forKey: 'language')

Generate access token Instagram API, without having to log in?

So I am building a restaurant app and one of the features I want is to allow a user of the app to see photos from a particular restaurant's Instagram account.
And I want a user to be able to see this without having to login to their Instagram account, so they shouldn't even need an Instagram account for this to work.
So I have read this answer How can I get a user's media from Instagram without authenticating as a user?
And I tried what it said and used the client_id(which I recieved when I registered my app using my personal Instagram account), but I still get an error back saying :
{
meta: {
error_type: "OAuthAccessTokenException",
code: 400,
error_message: "The access_token provided is invalid."
}
}
The endpoint I am trying to hit is :
https://api.instagram.com/v1/users/search?q=[USERNAME]&client_id=[CLIENT ID]
So do I absolutely need an access token for this to work(and thus have to enforce a user to log in) ?
If I do, then is there way to generate an access token somehow without forcing the user log in?
I believe there is a way around this, as the popular dating app Tinder has this desired functionality I am looking for, as it allows you to see photos from people's Instagram account without having to log in! (I have just verified this 5 minutes ago!)
Any help on this would be much appreciated.
Thanks.
Edit April 2018: After facebook privacy case this endpoint is immediately put out of service. It seems we need to parse the JSON embedded in <script> tag directly within the profile page:
<script type="text/javascript">window._sharedData = {"activity_counts":...
Any better ideas are welcome.
You can use the most recent link
GET https://www.instagram.com/{username}/?__a=1
to get latest 20 posts in JSON format. Hope you put this to good use.
edit: other ways aren't valid anymore:
https://www.instagram.com/{username}/media/
Instagram used to allow most API requests with just client_id and without access_token, the apps registered back in the day still work with way, thats how some apps are able to show instagram photos without user login.
Instagram has changes the API specification, so new apps will have to get access_token, older apps will have to change before June 2016.
One way you can work around this is by using access_token generated by your account to access photos. Login locally and get access_token, use this for all API calls, it should not change, unless u change password,if it expires, regenerate and update in your server.
Since the endpoints don't exist anymore I switched to a PHP library -
https://github.com/pgrimaud/instagram-user-feed
Installed this lib with composer:
composer require pgrimaud/instagram-user-feed "^4.0"
To get a feed object -
$cache = new Instagram\Storage\CacheManager();
$api = new Instagram\Api($cache);
$api->setUserName('myvetbox');
$feed = $api->getFeed();
Example of how to use that object -
foreach ($feed->medias as $key => $value) {
echo '<li><img src="'.$value->thumbnailSrc.'"></li>';
}

Get posts from page that hasn't setup a custom alias?

I'm visiting a number of Facebook pages and collecting information about their posts. When the Facebook page has created a custom username / alias, I can simply query their page like so, using their ID:
$accessToken = FACEBOOK_APP_ID.'|'.FACEBOOK_APP_SECRET;
$url = 'https://graph.facebook.com/104958162837/?access_token=' . $accessToken;
However, if they didn't bother to setup a custom username / alias, then it won't work, even if I specify:
The default alias that FB gave them when they created the page (looks something like My-Page-Name-104958162837).
The numerical ID of their page.
What gives?
Works fine for me that way, if use a User Token:
/129319107123637
/129319107123637/feed
Just try it in the API Explorer, after authorization: https://developers.facebook.com/tools/explorer/145634995501895?method=GET&path=129319107123637&version=v2.5
It only does not work with an App Token if the Page is restricted by age or location. In that case, you have to use a User Token of a User who is allowed to see the Page, of course.

Get user's gender using the old Facebook SDK

As you know facebook has moved to api 2.4, and now I can't get the user's gender with my previous code.
$f1 = new Fb_ypbox();
$user_data = $f1->getUserData();
$fb_user_id = $user_data['id'];
$name = $user_data['name];
$gender = $user_data['gender'];
$birthday = $user_data['birthday'];
Now this code only gets the user id & the usre name & his profile picture.
Not the gender or his birth date (although I have the extended permission of user_birthday).
Is there any chance to update my code or any other code to get the user's public info (gender for example) which doesn't request any extended permissions?
I just know that now it's not just making the GET request for "/me", but I also should add the "?fields=gender" addition.. I just can't manage to add it to my current sdk code.
I have read Facebook's API documentation couple of times and I can't figure it out..
Thanks :)
First of all you need to supply a more detailed description like the version of that "Fb_ypbox" class you are using. Probably there is a new version available that deals with the declarative fields changes in the 2.4 API already.
Since you did not supply these information we can only make a guess:
Search for "//graph.facebook.com/me?" in all class files and add the fields=name,gender,...

Cannot get page "like" status using Facebook C# SDK

I am using the latest Facebook C# SDK (v5.0.40 at time of writing) from here: http://facebooksdk.codeplex.com/.
I have created a test iFrame app in Facebook and got the CSASPNETFacebookApp sample running so that it displays the name of the currently logged in user within Facebook.
What I would now like to do is display different content in my iFrame depending on whether the user has "liked" the page. However the signed_request never seems to contain that information. From what I can see in the FacebookSignedRequest.cs I will only get the payload which contains the page information if the algorithm is AES-256-CBC HMAC-SHA256 but I only ever get HMAC-SHA256 returned.
What am I doing wrong? How do I get it to return the page information? Is it a problem with the setup of my app in Facebook or a configuration issue with the .NET app?
Thanks in advance.
var fb = new FacebookClient("access_token");
dynamic parameters = new ExpandoObject();
parameters.method = "pages.isFan";
parameters.page_id = "{you page id}";
dynamic result = fb.Get(parameters);
bool isFan = result == true;
Neil Knight's answer is technically correct, you can use FQL to look up whether a user has liked a page and it did help to set me on the right path. However my issue was actually more one of set up rather than code. What I didn't understand is that you only receive the "like" information in the signed request if your app is running within the "context of a page". If you set it up correctly then Facebook will pass your app the like flag without the user needing to "Allow" your app.
The steps are:
(1) Create your iframe application in Facebook
(2) Set up a tab url for your app in the app settings. This is what the parent page will use when it generates a link in the left hand column to go to your app.
(3) Go to your "App profile page", the URL will be something like this: http://www.facebook.com/apps/application.php?id=12345 Where 12345 is your app ID.
In the left hand column below the logo image there should be a link "Add to Page". If you click on that link you will be presented with a list of pages that you are the admin for. Select the page you want to like in your app.
Now if you navigate to your page you should get a link to your app in the left hand column. It is only when clicking on that link that you will get the page id and like status passed through to your application.
Hope this helps someone having the same issue.
You could use FQL in order to achieve this. I have just done this using the following statement:
var the_query = FB.Data.query("SELECT uid FROM page_fan WHERE page_id = {0} and uid={1}", page_id, user_id);
In order for this to work, I had to ask the user to "Allow" my application so that I had permission to check to see if they liked the page. Then, it was a simple case of checking the result and displaying the necessary <div>:
the_query.wait(function (rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
$("#myLikeContent").show();
} else {
$("#myNoLikeContent").show();
}
});