I want to understand the following code in Facebook? - facebook-graph-api

in the following code what is code variable and what is it purpose?
$code = $_REQUEST["code"];
if(empty($code)) {
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=create_event";
echo("<script>top.location.href='" . $auth_url . "'</script>");
}

This is a step of the OAuth process. You exchange the code with facebook to get an access token. You can read a far better explanation than I can write, here

$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=create_event";
echo("<script>top.location.href='" . $auth_url . "'</script>");
This part is facebook suggested way to show auth. dialog which comes up usually when you try to add application. It is dialog which asking permissions to use your email, photos, etc...
$code
is most likely variable which indicates on your application side whether user with particular email exists in your DB or not.If it is empty or false it means that user does not exist and for him application shows auth. dialog

Related

Save data created in OpenCart 2.3 event for later display

I see how to use an event to generate a controller call in OpenCart 2.3.
What I don't see is how to save the data created by the controller call for later use in a view.
How have other people handled this?
Not sure exactly what you want to do here but couldn't you just do something like:
file_put_contents(DIR_CACHE . __CLASS__ . __FUNCTION__ . md5(serialize($this->request->get)) . '.ser', serialize($data));
That would store everything in $data (which is everything that gets passed to the view) in a flat file named after the class and method and query parameters.
Then, for example, to recall later on a product page, just do:
if (file_exists(DIR_CACHE . __CLASS__ . __FUNCTION__ . md5(serialize($this->request->get)) . '.ser') {
$data = unserialize(file_get_contents(DIR_CACHE . __CLASS__ . __FUNCTION__ . md5(serialize($this->request->get)) . '.ser'));
$this->response->setOutput($this->load->view('product/product', $data));
}
Not sure if that answers your question but could could also just use Opencart's built in cache methods if you wanted it to expire at regular intervals.

How to load catalog model in admin controller

I am using Opencart Version 2.1.0.1, how to load frontend model in admin controller,
i have a model function which tells external booking id
class ModelShippingParcelled extends Model {
public function getParcelledBooking($order_id) {
$query = $this->db->query("SELECT booking_id FROM " . DB_PREFIX . "parcelled WHERE order_id = '" . (int)$order_id . "'");
return $query->row;
}
I want to load this model in admin controller. What is the best way to do this?
Should I rewrite this model in admin too? But I don't want to rewrite the same function. If there is a good way please suggest!
Well, there is one ugly trick to achieve what you want. Example if you want to use the frontend's catalog/product model from your admin controller, then you can:
require_once DIR_CATALOG . "model/catalog/product.php";
$product = new ModelCatalogProduct($this->registry);
This will work also when you want to use the admin model from the frontend controller, just change the require statement.
I also needed to call a function from catalog/model inside admin/model (without copying). Requiring a function occured to be imposible in php.
But I figured out that I can move the function into system/library, for example in /system/library/cart/cart.php.
Albeit cart functions is never called in admin it occured to be possible. So I called it like
$this->cart->functionName($params)
To make sure function is still working in catalog I made replacement via shell like
find catalog -type f -print0 | xargs -0 sed -i '' -e 's/this->model_catalog_filter->functionName/this->cart->functionName/g'
I suggest that you make a copy of the model in the admin folder.
And if you are sure which functions you are gonna use copy only them.

Error while printing Fedex return lable

I am newbie to fedex web-services API.
I want to print the return label with the out bound shipment. I tried including below tag under RequestedShipment/SpecialServicesRequested tag. but i am getting the error "Alternate sender not allowed with return shipments".
Here is my request look like..
<RequestedShipment>
.
.
<SpecialServicesRequested>
.
.
<ReturnShipmentDetail>
<ReturnType>PRINT_RETURN_LABEL</ReturnType>
</ReturnShipmentDetail>
.
.
</SpecialServicesRequested>
.
.
</RequestedShipment>
Thanks in advance...
Update : I am using fedex API 10.
When requesting return label, it should not have following two elements in request body.
LabelSpecification/ PrintedLabelOrigin/ Contact,
LabelSpecification/ PrintedLabelOrigin/ Address
Above elements are used to override return address from default value of shipping address.:)

How can I show the number of facebook likes for a page?

Let me start by saying that I'm a newbie to coding, so it's probable that I'm missing out on the absolute basics...
I'm working on a phtml file (done by professionals) and trying to show the number of likes for different facebook pages.
The query that does it is the following:
https://api.facebook.com/method/fql.query?query=select like_count from link_stat where url='https://www.facebook.com/'&format=json
and I tried to change the following code i found in order to do it
$fql_query_url = 'https://graph.facebook.com/'
. 'fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=me()'
. '&access_token=' . $access_token;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
like this:
$fql_query_url = 'https://graph.facebook.com/'
. 'fql?q=select like_count from link_stat where url='https://www.facebook.com/'&format=json';
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
I put it into a script and then I tried to call the variable but received an "undefined variable" error.
I'm not sure what am I doing wrong...
Is the code alright?
Does it go inside a script, inside a php code block or in something else?
Am I calling the variable correctly?
Sorry if there's any nonsense here, as I said, I'm just getting into it...
Thanks for your reply
See, there's a much easier way to obtain basic page data from facebook pages. If you know the ID or the slug of the page, query the graph api like this.
$fc = file_get_contents('http://graph.facebook.com/40796308305');
$pagedata = json_decode($fc);
?>
Coca Cola has <?php echo $pagedata->likes; ?> likes

How to to display the data that I have got from a form in django?

data = form.cleaned_data
rad1=form.cleaned_data['point']
I want to display both the data and rad1 , so as to know what is my form capturing . One way to do it send it as a value to the template to be displayed on the page . But I think there would be an easier way out . If I give a print 'data' . It doesn't print the data anywhere .
Text sent to stderr will appear in the web server's error log; it is best to use either logging or a logger supplied by the WSGI container for this.
If you want the text to appear in the browser then you will need to send it in the response, either as raw text or via a template.