I want to retrieve a Facebook user id if I have his username.
This was deprecated from the graph API but I would like to know a work around on getting the id if i have the username.
There is a website that does that but I am not sure how they do it.
I did the R&D and found that the given website is not using the API to fetch userid from the username.
They are using another mechanism which is not valid.
I have found 1 mechanism to find the userid from the username.
Below is the c# code which identify how to find userid from username.
I tried to read the HTML from facebook url. and trying to read below meta tag to identify userid.
META Code
<meta property="al:android:url" content="fb://profile/USERID">
Function
public string findUserIdfromUsername(string facebookURL)
{
try
{
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(facebookURL);
List<String> keyLst = doc.DocumentNode
.SelectSingleNode("//meta[#property='al:android:url']")
.Attributes["content"].Value
.Split(',').ToList();
foreach (string strkey in keyLst)
{
string[] arrTemp = strkey.Split('/');
int arrlength = arrTemp.Count();
string facebookUserID = arrlength > 0 ? (arrTemp[arrlength - 1]) : strkey;
facebookUserID = facebookUserID.Replace("?id=", "");
return facebookUserID;
}
}
catch (Exception ex)
{
}
return "";
}
Requirement
I have used "HtmlAgilityPack.dll" to load the html and parse it like XML.
To test call the function like below.
findUserIdfromUsername("https://facebook.com/USERNAME");
I have only test 3-4 urls and getting right userid.
I am not using any API to find USERID.
My English and steps are not too much good. So please manage it.
Related
Sorry this may be a trivial question but I am new to PHP. In the documentation to retrieve project tasks, the following code is provided to connect to an Active Collab cloud account:
<?php
require_once '/path/to/vendor/autoload.php';
// Provide name of your company, name of the app that you are developing, your email address and password.
$authenticator = new \ActiveCollab\SDK\Authenticator\Cloud('ACME Inc', 'My Awesome Application', 'you#acmeinc.com', 'hard to guess, easy to remember');
// Show all Active Collab 5 and up account that this user has access to.
print_r($authenticator->getAccounts());
// Show user details (first name, last name and avatar URL).
print_r($authenticator->getUser());
// Issue a token for account #123456789.
$token = $authenticator->issueToken(123456789);
// Did we get it?
if ($token instanceof \ActiveCollab\SDK\TokenInterface) {
print $token->getUrl() . "\n";
print $token->getToken() . "\n";
} else {
print "Invalid response\n";
die();
}
This works fine. I can then create a client to make API calls:
$client = new \ActiveCollab\SDK\Client($token);
and get the list of tasks for a given project as shown in the documentation.
$client->get('projects/65/tasks'); // PHP object
My question is, what methods/attributes are available to get the list of tasks? I can print the object using print_r() (print will obviously not work), and what I really want is in the raw_response header. This is private however and I cannot access it. How do I actually get the list of tasks (ex: the raw_response either has a string or json object)?
Thanks in advance.
There are several methods to work with body:
$response = $client->get('projects/65/tasks');
// Will output raw JSON, as string.
$response->getBody();
// Will output parsed JSON, as associative array.
print_r($response->getJson());
For full list of available response methods, please check ResponseInterface.
If you wish to loop through tasks, use something like this:
$response = $client->get('projects/65/tasks');
$parsed_json = $response->getJson();
if (!empty($parsed_json['tasks'])) {
foreach ($parsed_json['tasks'] as $task) {
print $task['name'] . "\n"
}
}
I searched for this but most of the questions related to this are for API's with other services.
I'm building an API that allows game developers to send and retrieve user info from my database.
I was finally able to put together the API, but now I need to call the API.
1st when the game initiates, it sends us the game developers key their developer id and game id.
//Game loads, get developer key, send token and current high score
// == [ FIRST FILTER - FILTER GET REQUEST ] == //
$_GET = array_map('_INPUT', $_GET); // filter all input
// ====================================== //
// ============[ ACTION MENU ]=========== //
// ====================================== //
if(!empty($_GET['action']) && !empty($_GET['user']) && !empty($_GET['key']) && !empty($_GET['email']) && !empty($_GET['password'])): // if key data exists
switch($_GET['action']):
//athenticate game developer return and high score
case 'authenticate':
$db = new PDO('mysql:host=localhost;dbname=xxxx', 'xxxx', 'xxxx');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$st = $db->prepare("SELECT * FROM `game_developers_games` WHERE `id` = :gameid AND `developer_id`=:user AND `key`= :key AND `developer_active` = '1'"); // need to filter for next auction
$st->bindParam(':user', $_GET['user']); // filter
$st->bindParam(':key', $_GET['key']); // filter
$st->execute();
$r = $st->fetch(PDO::FETCH_ASSOC);
if($st->rowCount() == 0):
$return = array('DBA_id'=>'0000');
echo json_encode($return);
else:
$token = initToken($_GET['key'],$_GET['user']);
if($token == $r['API_Token']):
$return = array(
'DBA_id'=>$token,
'DBA_servertime'=>time(),
'DBA_highscore'=>$r['score'],
);
echo json_encode($return);
endif;
endif;
break;
Here's the script the game developer will have to add to their game to get the data when the game loads. Found this on another stackoverflow question but it's not working.
$.getJSON("https://www.gamerholic.com/gamerholic_api/db_api_v1.php? user=1&key=6054abe3517a4da6db255e7fa27f4ba001083311&gameid=1&action=authenticate", function () {
alert("aaa");
});
Try adding &callback=? to the end of the url you are constructing. This will enable jsonp that is accepted by cors.
$.getJSON("https://www.gamerholic.com/gamerholic_api/db_api_v1.php?user=1&key=6054abe3517a4da6db255e7fa27f4ba001083311&gameid=1&action=authenticate&callback=?", function () {
alert("aaa");
});
As per cross domain origin policy you cannot access cross domain url using jquery getJson function.
A callback is required to manage cross domain request using json and it needs to be handled on the server as well as the client end.
Also make sure to check the response using firebug or similar tool because as of now it is returning response code as 200.
I am mentioning two threads here which can guide you the right way
Jquery getJSON cross domain problems
http://www.fbloggs.com/2010/07/09/how-to-access-cross-domain-data-with-ajax-using-jsonp-jquery-and-php/
I am creating a mobile app that needs to be connected with mysql. I used php to query it and got the data to my php page.. I would like to bind this data with the list box in my windows phone 7. I am very new to this kind of programming and would like to how to get the data from the php page and bind it with the list box in my wp7 app.. I managed to print the data using webclient in a messagebox in wp7 app.. but i would like to bind it to the list box... please help....
My code:
public Article()
{
InitializeComponent();
WebClient wc = new WebClient();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(printlist);
wc.DownloadStringAsync(new Uri("http://www.skbcreations.com/app/Pushnotification.php") );
return;
}
void printlist(object sender, DownloadStringCompletedEventArgs e)
{
string res = (String)e.Result;
MessageBox.Show(res);
}
My XAML:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.061*"/>
<ColumnDefinition Width="0.939*"/>
</Grid.ColumnDefinitions>
<ListBox Grid.Column="1" Margin="24,28,36,56"/>
</Grid>
Which format has your response?
If XML, you could use this one:
XElement xmlItems = XElement.Parse(e.Result);
var items = from item in xmlItems.Descendants("item-element-name")
select new Item
{
field1 = item.Element("field1").Value,
field2 = item.Element("field2").Value
};
listBox.ItemsSource = items.ToList();
Also, consider to use ObservableCollection if your list will be changing in run-time
I'm trying to determine whether the user name and password I've sent to a php login form is valid. I've read some posts that suggest looking at the response text and checking for the title of the page that is returned. Other posts mention using a session ID in some way. Just what is the best way to detrmine if the user name/password combo is valid once I've posted to the form? Any help would be greatly appreciated. Thanks in advance.
Update...
I was able to resolve this issue using the following code snippet:
response = httpClient.execute(httpPost);
cookies = ((AbstractHttpClient) httpClient).getCookieStore ();
myCookie = cookies.getCookies ();
// if cookies are empty, login did not work.
if (!myCookie.isEmpty ())
{
for (int i = 0; i < myCookie.size(); i++)
{
String str = myCookie.get(i).toString();
// look for PHP session cookie and save it.
if (str.contains ("PHPSESSID"))
{
phpsessid = myCookie.get (i).toString ();
int index = phpsessid.indexOf("value");
phpsessidGuid = phpsessid.substring(index+7, index+39);
}
}
}
Hope this helps others with the same problem.
Okay normally I'm all fine about the facebook API but I'm having a problem which just keeps me wondering. (I think it's a bug (Check ticket http://bugs.developers.facebook.net/show_bug.cgi?id=13694) but I wanted to throw it here if somebody has an idea).
I'm usng the facebook PHP library to count all attendees for a specific event
$attending = $facebook->api('/'.$fbparams['eventId'].'/attending');
this works without a problem it correctly returns an array with all attendees...
now heres the problem:
This event has about 18.000 attendees right now.
The api call returns a max number of 992 attendees (and not 18000 as it should).
I tried
$attending = $facebook->api('/'.$fbparams['eventId'].'/attending?limit=20000');
for testing but it doesn't change anything.
So my actual question is:
If I can't get it to work by using the graph api what would be a good alternative? (Parsing the html of the event page maybe?) Right now I'm changing the value by hand every few hours which is tedious and unnecessary.
Actually there are two parameters, limit and offset. I think that you will have to play with both and continue making calls until one returns less than the max. limit.
Something like this, but in a recursive approach (I'm writting pseudo-code):
offset = 0;
maxLimit = 992;
totalAttendees = count(result)
if (totalAttendees >= maxLimit)
{
// do your stuff with each attendee
offset += totalAttendees;
// make a new call with the updated offset
// and check again
}
I've searched a lot and this is how I fixed it:
The requested URL should look something like this.
Here is where you can test it and here is the code I used:
function events_get_facebook_data($event_id) {
if (!$event_id) {
return false;
}
$token = klicango_friends_facebook_token();
if ($token) {
$parameters['access_token'] = $token;
$parameters['fields']= 'attending_count,invited_count';
$graph_url = url('https://graph.facebook.com/v2.2/' . $event_id , array('absolute' => TRUE, 'query' => $parameters));
$graph_result = drupal_http_request($graph_url, array(), 'GET');
if(is_object($graph_result) && !empty($graph_result->data)) {
$data = json_decode($graph_result->data);
$going = $data->attending_count;
$invited = $data->invited_count;
return array('going' => $going, 'invited' => $invited);
}
return false;
}
return false;
}
Try
SELECT eid , attending_count, unsure_count,all_members_count FROM event WHERE eid ="event"