FQL Testing Tool Vanished? - testing

This is my first post here, so I should probably start by saying thankyou for the myriad of issues you have helped me to resolve.
http://developers.facebook.com/docs/reference/rest/fql.query/
The fql.query page had a utility that allowed you to build FQL statements and test their results using one of your Applications access tokens. Is it just me or has it vanished?

You now use the Graph API Explorer tool for testing everything.
In the large dialog box, you type fql?q= followed by your query. e.g: fql?q=SELECT username FROM user WHERE uid = me()
There are other buttons that let you use a custom access token or one of your page's tokens methods.

agrees with cpilko, use the Graph API Explorer.
You can bookmark this link instead, It auto switches the tab to FQL https://developers.facebook.com/tools/explorer?fql

Related

Send an initial message when people first invite the Telegram bot

I am using Python and have previously built Telegram chatbot before.
However, now I want to create a chatbot such that when someone invites it, it will send an initial message that says something like "type /start for instructions".
This is to make sure that they know what to do when they first invite the bot. Can this be possibly done?
I am trying to use bot.send_message(chat_id=chat_id, text="type /start for instructions") but the problem is I don't know how I could obtain the chat_id.
Unfortunately, you cannot do it :(
Here has another way you might interested: /setdescription in #BotFather.
It will be shown in the What can this bot do? section as the picture below.
After digging this issue - here's what I've found:
The reason:
Intuitively it seems logical to allow a feature that sends a message to a user (as a reaction to the user's action for starting the chat). BUT, because telegram APIs are truly vast there is a fair chance for abuse in this format (a message with button that drives the user for action without the user truly understand the consequences). From here my question changed from "how to implement this mechanism?" to "Which alternative do I have?"
There is an alternative!
My initial goal was to make the "what can I do here" factor as clear and effortless to the user as possible. Technically speaking - all methods that can be invoked without the chat_id can be invoked as part of your bot setup process and will affect all users. One option is to create a list of commands to your bot. This list will appear when the user use the / operator and it's a common practice among chat users. For my intention - I needed something even simpler than that and I think that the setChatMenuButton is very suitable. This method allows you to create a web app and allows the user to simply click it instead of typing text. When clicking the button it triggers a dialog that clarifies to the user what's going on and from there - it's basically your imagination that will define how the end-user will experience your process. I managed to execute this call using a wrapper that I've build (which handles the base url as well as secret key) using this code:
await api.get('setChatMenuButton', {
menu_button: JSON.stringify({
type: 'web_app',
text: 'Name of your app here',
web_app: { url: 'https://your-domain.com/ppp/path/goes/here' }
}),
})
More about Telegram Web Apps
And a little screenshot from my experience:

How to retrieve Salesforce Page Layout Field Properties via API?

Context:
The Web interface coded in .NET (Grantee Portal for nonprofits applying for grants) is pulling information from the Salesforce Page Layout.
The Salesforce user we use to connect the Web interface with Salesforce via API has 'view all and edit all' rights
Issue:
As it is now, if a field is defined as Read-Only on the Page Layout in Salesforce, it is still editable on the web page (the Salesforce User we use has to have 'view all and edit all' rights)
What we are trying to achieve:
IF a field is defined as Read-Only on the Salesforce Page Layout
THEN the same field should be Read-Only on the Web interface page
Question:
To achieve the above, I guess that I need to fetch the field property for the Page Layout via API. Any ideas on how to do so?
Thank you!
Izumi.
You'll need Metadata API (the set of webservices that let you add new objects, fields, picklist values or even create classes & run unit tests).
Here's the API Guide: http://www.salesforce.com/us/developer/docs/api_meta/index.htm
Depending on how often you modify layouts you might decide "screw it, I'll just use Eclipse IDE". In that case you'd download all page layouts (they're XML files), point your C# app to them and let the magic happen.
Slightly more advanced is to use Migration Tool (Ant / Java based application that can be scripted for periodic download of same stuff).
Super advanced would be to use this API guide to write it in C#. It's not rocket science (here's the specification for Page Layout object and here's the Java sample code for the operation that retrieves the metadata... sorry, no C#). Actually you might be better off looking at this example though: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_describelayout.htm
Seeing that you'll probably want to cache this info somewhere anyway (I can't imagine your user coming to your page, having to wait for the webservice callout to complete, then having his UI rendered) - pick your poison.
Or share the work within the team (1 person kicks off with files downloaded with Eclipse, other tries to figure out the C# code to retrieve them on demand).

Google+ .Net API - Getting Authenticated and retrieving profile

I'm trying to get a users profile information for google+ via the .NET API but am having trouble.
Does anyone know if they have changed how the special ID "me" works?
In the documentation it says this can be used as a special ID to get the currently authenticated users information however this throws a 404 from both the API in my code and on Google's own test page https://developers.google.com/+/api/latest/people/get. I was logged in when trying this.
Does anyone know how to get the user ID as I would happily use that instead of me but it isn't returned after the user authenticates as far as I can see (just an authcode)?
I also tried using user IDs returned when using the standard .net Oauth stuff but it isn't the correct ID, I assume it is for something else.
As for my method of getting to this stage, I first downloaded the example files here: http://code.google.com/p/google-api-dotnet-client/wiki/GettingStarted
They don't have a plus example so I took the Tasks.ASP.NET.SimpleOAuth2 example and swapped out tasks (which worked fine) for the plus equivalent.
I also tried rolling this into my own project.
Neither worked. I get the user forwarded to Google where they give me access fine and then when I return they are authenticated successfully as far as I can see, however when I call service.People.Get("me") it returns a 404.
If anyone could help with the above questions (using me, or gettign the user ID) I would appreciate it.
To the moderator who closed the initial version of this question, I have tried to make this as direct a question as possible so please don't close it. This is a legitimate question I would really like help getting to he bottom of.
This is now out of date given recent platform updates. Although the plus.me scope still exists and this code will work, you should be using the plus.login scope for retrieving profile data in C#. For a great way to get started with retrieving and rendering profile information, please start from the Google+ C# quick start available here:
https://developers.google.com/+/quickstart/csharp
First off, the 'me' id still works and is unchanged. The way that it works is:
You authenticate the user using a standard OAUTH2 flow
You use the library to perform a People.get with the special value 'me'
The 404 error code is a little troubling, this means that the client isn't finding the endpoint. To debug this, you might want to use a packet sniffer like fiddler to see what the actual URL it's querying is.
Anyways, how about some C# code. The following example shows how to use the plus service to get the currently authenticated user (assuming you have authenticated someone). What's different from your snippet is that you need to form a get request for the API call, then run fetch on the get request. I've included the following example, for getting 'me', and the following code works:
var auth = CreateAuthenticator();
plusService = new PlusService(auth);
if (plusService != null)
{
PeopleResource.GetRequest prgr = plusService.People.Get("me");
Person me = prgr.Fetch();
}
All of the configuration of the server and getting a client working is pretty hard and pasting all of the code here would be less helpful than just giving you a sample.
And so... I have written a sample application that demonstrates how to do this and also includes a wrapper that makes it easier to develop using the Google+ API in C#. Grab it here:
Google+ C# Server-Side demo and library
Seems you need to use:
Person test = service.People.Get("me").Fetch();
and not
req = service.People.Get("me");
Person test = req.Fetch();
Even though they seem to be identical the first works and the second doesn't.
Still not sure why google's own page doesn't work though. Now to find out how to add things to the scope like birthday.

How might I provided a URL use the FireShot API to take a screenshot, upload to Imgur, and return some output (eg. markdown)

I am looking for a way to utilize the FireShot API with JS to given a URL (or perhaps a list) use the FireShot API to take screenshot, upload to Imgur, then return the user the URLs or perhaps something like markdown to use quickly in forums.
Method 1: Open new window
I tried opening the URL in a new window, but found that I cant control that page with JS dues to cross domain problems. The same with iFrames.
Method 2: simple $.get()
A simple $.get() wont work because of the same cross domain issues I guess?
http://jsfiddle.net/t6aeq/
$.get($url.val(), function(data) {
console.log(data);
});
Via PHP "Proxy"
So I tried creating a simple PHP script that gets the HTML of the URL and returns it to my JS (using file_get_contents($url)). But some sites like Microsoft will detect that I am using some automated methods and give an error page of sorts. I also cant seem to find a way to use jQuery to query that returned HTML for link[rel=stylesheet], script, style and body to append to the head and a div respectively. I posted abt that on another question
A new Idea: Embed scripts on browser level
So I thought away of getting around these is using iMacros or GreeseMonkey or something to insert scripts into pages on the browser level instead? But any guidance or tips on how can I do that? Also, I'd prefer a pure JS/PHP method if available so users are not limited to using Browser plugin/scripts (tho I will be the only user for now)
It suddenly came to my mind that this may not work because the FireShot API key and Imgur is limited to the domain? Any solutions?
You might be able to inject the FireShot script using Greasemonkey. But, first use GM_xmlhttpRequest() to fetch an API key, for that page's domain, from the "Create FireShot API Key" page.
Note that GM_xmlhttpRequest() does not have the same cross-domain issues that $.get() has.
However, at this point you might be better off just writing your own Firefox add-on. Maybe start with FireShot's code for ideas. Also see the Screengrab add-on.

REST API for driving distance?

Is there a service that will give me the driving distance between two addresses? Apparently Google Maps API requires you to display a map, which I don't want to do (on that particular page), and I'd like to just snag the data and save it to my DB after a user submits a form, rather than waiting for JS to do it's thing.
If it's relevant, this is going into a Django app. I discovered that CloudMade offers a Python API, which is nice, except their latest dev release has a bug in it (can't use the API object), but more importantly, it's support for Canada is awful (couldn't find directions from any major city around here!).
MapQuest's Directions API is HTTP Querystring based (I'm not sure if it's entirely RESTful). Can get XML or JSON response. Just need to send it an HTTP GET Request.
http://developer.mapquest.com/web/products/open/directions-service
Use the "distance" response parameter.
I don't have a high enough reputation on SO to comment on an answer but I just wanted to be clear that contrary to the voted correct answer, Google Directions API has to adhere to the Google Maps API. If you scroll down the supplied link, you will see:
Note: the Directions API may only be used in conjunction with displaying results on a Google map; using Directions data without displaying a map for which directions data was requested is prohibited. Additionally, calculation of directions generates copyrights and warnings which must be displayed to the user in some fashion. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions.
Would it be possible to use Google Maps GDirections object? This can return the textual directions instead of the map overlay if called with a div object. From there you can use the getDistance (or getDuration) functions. You can always use an invisible div for the returns if you don't want anything to be displayed on the page.
Start here
http://code.google.com/apis/maps/documentation/examples/directions-advanced.html
http://code.google.com/apis/maps/documentation/reference.html#GDirections
And use this sample code
var map;
var directionsPanel;
var directions;
function initialize() {
directionsPanel = document.getElementById("route");
directions = new GDirections(null, directionsPanel);
GEvent.addListener(directions , "load", onGDirectionsLoad);
directions.load("from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)");
}
function onGDirectionsLoad(){
alert(directions.getDistance().html);
}
Here is my solution:
Signup for Mapquest Developer network.
Get AppId
Open your command shell and run the following command(or use fiddler) But running it through curl will give you flexibility to automate your request
curl -X POST -H "Content-Type: application/json" -d '{locations: ["Salt Lake City, UT","Ogden, UT",],options: {allToAll: false}}' http://www.mapquestapi.com/directions/v2/routematrix?key=YOURKEYGOESHERE >> distance.txt
Save above command with all your destinations into batch or sh file.
Now grep and parse out your distance.txt file for what you need.
There are free services out there, but the quality of the data may be questionable/non-existent in areas. Be aware of licences on the data too, storing in your own DB may be a breach.
http://openrouteservice.org/
Take a look at Navteq. I used their service in developing a driving directions application about 5 years ago, and got good results. Can't speak for them lately though. I believe the best URL is Navteq Routing Service
You can use the new Google Directions API directly, without using any javascript.
http://code.google.com/apis/maps/documentation/directions/