Get Facebook Status from Fan Page using API - json

I've been trying to get the most recent Facebook Status for a fan page via the API for a while now and can't seem to get what I'm after. I'm really trying to avoid using RSS for it. I can get the full list from the feed via https://graph.facebook.com/174690270761/feed but I want only the last status posted by the page admin, not by anyone else.
Is their an easy way to get it without having to authenticate?
Thanks in advance
edit:
https://graph.facebook.com/174690270761/statuses seems to be what I'm looking for but I need an OAuthAccessToken for this but can't see how to without involving the user, as I'm trying to access through my own credentials/application

Facebook has changed the api and now requires you to provide an access token.
You can use Facebooks PHP sdk for that but i found a much quicker way to go:
<?
$appid = '1234567890';
$secret = 'db19c5379c7d5b0c79c7f05dd46da66c';
$pageid = 'Google';
$token = file_get_contents('https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id='.$appid.'&client_secret='.$secret);
$feed = file_get_contents('https://graph.facebook.com/'.$pageid.'/feed&'.$token);
print_r(json_decode($feed));
?>
Update 15/12/12
app access tokens nosist of the id and secret now - use this request:
$feed = file_get_contents('https://graph.facebook.com/Saxity/feed?access_token='.$appid.'|'.$secret);

I finally found out that this doesn't have to be done through the API, or require any authentication at all.
Basically you can access the data via a JSON feed:
$pageID = "ID of Page" //supply the Id of the fan page you want to access
$url = "https://graph.facebook.com/". $pageID ."/feed";
$json = file_get_contents($url);
$jsonData = json_decode($json);
foreach($jsonData->data as $val) {
if($val->from->id == $pageID) { //find the first matching post/status by a fan page admin
$message = $val->message;
echo $message;
break; //stop looping on most recent status posted by page admin
}
}

I don't think there's a good way to do this. You can process the JSON pretty easily though from the looks of it. You can limit the number of results by using the since query parameter. For instance:
https://graph.facebook.com/174690270761/feed?since=last%20Monday
You can also use limit on that, but I don't think that filters by user. If the administrator is the only one allowed to post, then you may be able to get away with using limit=1.

Related

Symfony ivory google map photos url

I want to display a photo of a google place. I'm using below code to get the information about a place
$request = new PlaceDetailRequest($placeID);
$response = $this->container->get('ivory.google_map.place_detail')->process($request);
Its Working fine.
With $response->getResult()->getPhotos()[0]->getReference() I get the reference to the first photo.
Now to get the real URL of this photo I have to call
https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=PHOTOReference&key=YOUR_API_KEY
To get this I using below code
$requestPhoto = new PlacePhotoRequest($placeID);
$responsePhoto = $this->container->get('ivory.google_map.place_photo')->process($requestPhoto);
and get below error:
You have requested a non-existent service "ivory.google_map.place_photo". Did you mean this: "ivory.google_map.place_detail"?
Can anybody help me? Or: How can I get the URL on a different way?
OK, found the problem: It was a misconfiguration of the config.yml. I had an empty line before 'place_photo'
ivory_google_map:
place_detail:
client: httplug.client.default
message_factory: httplug.message_factory.default
format: json
api_key:
place_photo:

Wordpress REST API search products

Hope that you can help me.
I have a website that runs wooccommerce. I am using the woocommerce rest api. Now on another website what I want to do is create a simple search field where I type something and the search form needs to search through the woocommerce website and return results.
Is there a way I can achieve that ?
Try this:
/wp-json/wc/v2/products?search={{product_name}}
Works for me.
I think no.
The New Version of WooCommerce API (v2) is supports id based calls.
so instead you can get a list of abstract product details in your 2nd website and call back via product id.
/wp-json/wc/v2/products?search={{product_name}}
Is this function working if you are looking a exact product?
If you have a product like MR2050 and another with MR2050K, the result is not as you may expected, cause API rest will return 2 products, not just ONE?
If you use a wc-api-php (PHP library), please follow like this :
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'http://mydomain', // Your store URL
'ck_****', // Your consumer key
'cs_****', // Your consumer secret
[
'wp_api' => true, // Enable the WP REST API integration
'version' => 'wc/v3' // WooCommerce WP REST API version
]
);
echo "<pre>";
print_r($woocommerce->get('products', ['search' => 'key word']));
echo "</pre>";
This works for me in 2021:
/wp-json/wc/v3/products?search={{productName}}
productName - refers to the input that you enter in the Search box

How should I edit a model entry in mvc?

I am working on a small app using phalcon for php framework. I have implemented multiple controllers and models, but so far when I want to edit a user for example, i use a link that links to
localhost/myappname/User/edit/11 "user's id"
I was told this is not the best way to do this, and I am trying to do this without passing the id through the url, like using post method like in forms but without success so far.
Is this the only correct way to edit or delete an entry or it there something better?
I tried to search for the problem but couldn't figure how to name this question so I am yet to find an answered question.
If you don't want to let everyone access to edit page you can do this in a few ways.
Solution #1
You can use Phalcon ACL to block user's who has no permission to edit this page so only allowed people like managers can edit user or whatever.
See Access Control Lists ACL
Solution #2
You can crypt/decrypt user id so in URL it will not be readable by humans and then in edit method try to dectypt that id and if it is not a valid echo error.
<?php
use Phalcon\Crypt;
// Create an instance
$crypt = new Crypt();
$key = 'le password';
$user_id = 5;
$encrypt = $crypt->encryptBase64($user_id, $key);
// Use $encrypt for URL like Edit
// Use decrypt to get the real id of a user
$crypt->decryptBase64($encrypt, $key);
?>
In this way users will see URL something like
localhost/myappname/User/edit/nomGPPXd+gAEazAP8ERF2umTrfl9GhDw1lxVvf39sGKF34AFNzok31VdaT/OwADPPJ4XgaUNClQKrlc/2MfaXQ==
For more info see Encryption/Decryption
But my personal opinion is that it is better to go with ACL. After all ACL was made for that kind of things.
Note! If you want to use Encrypt/Decript remember to wrap decryption
in edit method in try/catch block and catch exception so you don't
get Error if someone tries to guess sone id.
Solution #3
If you still want to do that using POST then don't use Edit instead you can try something like:
<form method="POST">
<input type="hidden" name="uid" value="{{ user_id }}"/>
<button type="submit">Edit</button>
</form>
And then in edit method catch that id like:
<?php
$user_id = $this->request->getPost("uid");
?>
NOTE! In this way your URL will not contain user id but someone still
can POST another uid so you can try to hide that real user id even
from input type hidden. You can use again crypt/decrypt so input
hidden uid can be crypted and then decrypt post data in method.
you could use sessionStorage. It would store the value of the userId in the browser and be deleted as soon as they leave the page.
http://www.w3schools.com/html/html5_webstorage.asp
set on one page
sessionStorage.userId = 11;
access on another
var user = sessionStoarge.userId;

Bolt: saveContent updates values but doesn't actually save the record

I'm trying to create new content with:
// Get suggestions template and update with values
$content = $this->app['storage']->getEmptyContent('suggestions');
$content->values['title'] = $title;
$content->values['description'] = $description;
// Save to db
$save = $this->app['storage']->saveContent($content);
status is set as publish in data returned from getEmptyContent.
When I visit the backend, I can see that the save status is None. How can I actually create it so that it is published?.
This sounds like it could be a bug since as far as I can remember some value should make it through to status by default. One thing to check, in your contenttypes.yml file for suggestions you can also add a default_status eg:
default_status: publish
If you still have no luck then raise an issue on Github.

Send an integer into a server with GET method

I've been researching this problem for a while now and have been trying to use the POST method until recently when I figured out that the GET method will be sufficient for what I need to do.
My objective:
Take an integer from my app and send it into a php server to save it
For now, I just need to send one integer to get it working and to have a starting point to work from. Once I start getting the ball rolling and things start working, I will be sending maybe 20 integers maximum at a time, so I don't believe that I will have a problem with the data amount restrictions on the GET method.
I am working with a friend on this project right now because I am not as fluent in php, I have been exposed to it several times though, so I should know most of the terminology involved. ANYWAY, here is my php code that my friend wrote for me...
<?php
// A sample php file to demo passing parameters and getting POST data.
// This simply appends the specified value to the end of the 'sample' table.
// Call it like this: sample.php?val=4
// where 4 is the value you want to append to the table
// The code returns whether or not the sql query was performed with success or not.
// If successful, a boolean true (or 1) is returned.
// If not, then an error message is returned with the sql error.
include 'dbConnect.php';
$val = $_GET["val"]; // value to set to
$sql=
"INSERT INTO sample (`test`)
VALUES ('" . $val . "')
";
$result = mysql_query($sql,$con);
if(!$result){
die('Error: ' . mysql_error());
}
echo $val+1;
mysql_close($con);
?>
This code takes the sent value for the variable "val" and echoes that value plus one (so that the setting and the getting values are different from the site so I can more easily tell if my code works) This should work right?
Next, I believe I haven't quite finished the Xcode portion of the project yet, but I have a successful connection happening, I just haven't been able to change the value of the variable in the php server. In my project, I have an NSInteger variable called "num" and its value, set by the text field in my app, is the one I want to send in to the server. I also am using a button (called "postPressed") to initiate the function of the sending process. So here is my code...
NSURLRequest *request;
NSURLConnection *connection;
NSURL *url;
NSInteger num;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (IBAction)valueChange:(id)sender {
num = [_valueTF.text intValue];
}
- (IBAction)postPressed:(id)sender {
url = [NSURL URLWithString: [NSString stringWithFormat: #"http://jrl.teamdriven.us/source/scripts/2013/sample.php?val=%d", num]];
request = [NSURLRequest requestWithURL:url];
if (request) {
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
_returnLbl.text = #"success!";
}
}
My returnLbl does change to be "success", so I know the connection works, I just think I'm missing some code on the setting the variable part. Please help me out, this has been a thorn in my side for about a month now. Also, I apologize for the length of this question, I'm just trying to get in all the details so that there doesn't have to be any clarifications.
So, it turns out that my code worked the whole time, it's just that when I looked up the data table generated by phpMyAdmin, I did not happen to notice that there was a page two of data because I had tested it so much in my browser. The integers were sent and saved successfully with the code above. I apologize for posting something like this and finding out how dumb of a mistake it truly was, but if anyone would like to give me any kinds of improvements, I am open to them. Thank you for taking your time to view this question.