Open subhanahmed047 opened 8 years ago
Please see other threads in issues. There is some good info in there to get you out of the oauth issue.
Post a screenshot of your developer dashboard for your app. You may have a setup issue. Many times I see it this as a misconfig.
Here is my developers dashboard app settings
Your application URL is the callback URL, the redirection URL needs to point to where you want the user to go after oauth. I think this may cause a redirect loop as the app keeps passing it back to the redirect which is the same page you are loading. (this can be done like this but you need to test a query param to get you to step 3 of the process.).
first thing I would do is make the redirect point to get_products.php
also you should debug by changing this on line 13 of install.php
echo "<script> top.location.href='$install_url'</script>";
to this
echo $install_url;
See where it is trying to take you. you can inspect the url for the correct params
see this https://www.shopify.com/partners/blog/17056443-how-to-generate-a-shopify-api-token
I'm stuck here http://stackoverflow.com/questions/36234627/shopify-generating-a-shopify-api-token-this-request-is-not-from-shopify
Can you please help.
What is the install_url var?
I replied to your stack overflow question.
That article is approaching 2 years old from shopify. I did a recent test and localhost will not work as it is not ssl protected the redirect simply fails. If you are using this lib, try dumping your $install_url var and copy/paste into your browser. Navigate to that url manually and post it back here so I can inspect it. (you can delete or mask the domain, I just need to see query string).
It successfully generates a token when it redirects to generate_token.php but after that, the check that md5($signature_data) and $signature are same fails.
Here is my redirect URI variable that is appended to install_url
$redirect_uri = "https://xxxxxxxxx.herokuapp.com/generate_token.php";
Here is install_url var
$install_url = "https://" . SHOP_NAME . ".myshopify.com/admin/oauth/authorize?client_id=" . API_KEY . "&scope=" . SCOPES . "&redirect_uri=" . urlencode($redirect_uri);
I think you need to start from scratch and not follow the 2 year old article https://www.shopify.com/partners/blog/17056443-how-to-generate-a-shopify-api-token (this will work but not on localhost and not mixed with the code from shopify_app-skeleton.) You should use one or the other to get an understanding how the oauth works. The article was only intended as a tutorial to help you see the steps that this app skeleton takes to install the app. Separate the two.
Also, I noticed that you are using heroku which is great but this library uses composer to make sure all dependencies are installed. Can you post your launch logs from heroku? Maybe composer is failing and not installing all your components.
Guys follow this steps:
You are ready to install the APP
Edit and add this to conf.php
define('REDIRECT_URL', 'http://mysite.com/app/myapp/oauth.php');
(You can define the redirect url to whatever you want for now, in this case I'm sending them back to the website my app is hosted at.) !!!!!IMPORTANT!!!!!!! You must define this\ exact url **in your APP settings in your Shopify developer account. (Redirection URL (required)), else you will get the the redirection address not white listed error.
-$permission_url = shopify\authorization_url($_GET['shop'], SHOPIFY_APP_API_KEY, array('read_content', 'write_content', 'read_themes', 'write_themes', 'read_products', 'write_products', 'read_customers', 'write_customers', 'read_orders', 'write_orders', 'read_script_tags', 'write_script_tags', 'read_fulfillments', 'write_fulfillments', 'read_shipping', 'write_shipping')); to -$permission_url = shopify\authorization_url($_GET['shop'], SHOPIFY_APP_API_KEY, array('read_content', 'write_content', 'read_themes', 'write_themes', 'read_products', 'write_products', 'read_customers', 'write_customers', 'read_orders', 'write_orders', 'read_script_tags', 'write_script_tags', 'read_fulfillments', 'write_fulfillments', 'read_shipping', 'write_shipping'),REDIRECT_URL);
_Edit: Quick note, if you use underscores on your redirect file name, it might cause random errors. _
What is next? Learn and play with this to create a useful app. Now I'm trying to figure out how to modify the behavior of my shopify fronted with this app, for example what if I would like to change the rates that are shown during the checkout page, would I need to create a embedded app? Any suggestions or guidance would be appreciated! I will post my findings here.
@daniel-farina Unless you have a Plus account on Shopify, you can not change anything on the checkout with the API. Your instructions are great and should help @incredibleX but this has been covered multiple times in other issues of this project. see https://github.com/phpish/shopify_app-skeleton/issues/9#issuecomment-147216952
The embedded app just keeps the admin in the backend of the shop instead of opening a new tab. For example when I click the app in the apps section here: It opens in the backend.
I think you are needing an App Proxy URL setup so you can feed content (rate changes in your example) to the frontend of the shop.
@myjanky
Thank you for your feedback.
So the app being embeded or not it still has the same level of access to Shopify. Makes sense!
I think you are right about App Proxies. I'm reading this: https://docs.shopify.com/api/tutorials/application-proxies
and this is exactly what I'm looking for. Its a entire beast by itself. Lets see how far I can get.
This is how I do it:
var base_urlc = window.location.hostname; var window_width = $(window).width(); if ($('#customized').length > 0 ){ $('#customized').css({'width':'100%'}); // detect container width var width_canvas = $('#customized').width(); var product_id = $('#customized').data('product'); $.get( '/products/' + product_id + '.json', function(xhr,status){ data_params = JSON.stringify(xhr); data_param=JSON.parse(data_params); var product_id = data_param.product.id; var img_lrg = Shopify.resizeImage(data_param.product.images[0].src, 'large'); var target_html = '<iframe id="customized-iframe" src="//' + base_urlc + '/apps/customize?shop=' + Shopify.shop + '&product_id=' + product_id + '&image=' + img_lrg + '" frameborder="0" scrolling="no" style="display:block;" width="100%" />'; $('#customized').html(target_html); });}
@daniel-farina I followed everything you suggested. I clone and uploaded phpish/shopify_app-skeleton on the server.
Edited everything, My App callback url is exactly the same as redirect url but when i browsed to install.php with shop, like:
xxxxxx.com/shopify/install.php?shop=xxxxxxx.myshopify.com
I get this
Oauth error invalid_request: The redirect_uri is missing or not whitelisted
I've print_r my permission url and it is:
@myjanky I've cloned heroku git repo to my local system many times to see if everything is okay, and I havn't seen any composer issue.
Have you tried entering in this URL when logged in to shopify? Just navigate to this URL and see if it allows you to login. (you may have to change your redirect by removing ouath.php)
Yes, i'm logged in, but still getting this error
Yes it asks me to login first, but after login error page apears. The callback url is to oauth.php
Here are my App Settings:
Here is my redirect URI:
define('REDIRECT_URL', 'https://xxxxxxxxx.herokuapp.com/oauth.php');
define('REDIRECT_URL', 'https://xxxxxxxxx.herokuapp.com/oauth.php'); Make sure you change line 18: $permission_url = $permission_url . '&redirect_uri=REDIRECT_URL' as suggested above as well. You can save the variable in conf.php to make them global if you decide to add more redirects.
Here is my permission Url
$permission_url = shopify\authorization_url($_GET['shop'], SHOPIFY_APP_API_KEY, array('read_content', 'read_themes', 'read_products', 'read_customers', 'read_orders', 'read_script_tags', 'read_fulfillments', 'read_shipping'),REDIRECT_URL);
I've Even tried it this way: Changing line 18 to: $permission_url = $permission_url . '&redirect_uri='.REDIRECT_URL;
but no luck,
it has to match here as well. it can not be different.
Thanks a Lot for your kind support and patience :) That worked. :+1:
awesome. I am glad it worked for you. Let me know if you need anything else.
Sure, You're awesome :)
Help will save the world :earth_asia:
@incredibleX Than you for your help.
I got this sample app to work. Its very useful!
Dan
Hello,
I have followed all the steps and Installed App into Store. But after installed when I click on the store it redirects to the another tab. I have attached image of my App "Save & Share" on Store:
When I click on "Save & Share" App, then 2 urls are swapping continuously in one tab. Below 2 URLs are swapping:
Please give me solution. Why these two URLs are swapping in the single tab? I have no idea where is the problem.
It looks like you may have an SSL problem and a redirect problem. I can not say for sure what your exact error is without more information on your code.
One thing is that it is opening in a new tab. Do you have the embedded app checkbox check in the partners dashboard? Are you using a redirect?
read here https://help.shopify.com/api/sdks/embedded-app-sdk/getting-started (you will want to use the oauth method and not the auth method)
Thanks for the response.
I have used the same code for the App which is given by shopify_app-skeleton. I have add define('REDIRECT_URL', 'http://localhost/shopify/app1/new_prj/install.php'); into conf.php file. Still I have the problem to access App into the store and getting the same problem.
Sorry, I get that error after click on "Install App" from the Store dashboard. Means after running this link: http://localhost/shopify/app1/new_prj/install.php?shop=fashionstar-3.myshopify.com It redirects to store screen where a user clicks on "Install App".
After click on "Install App" it gives me blank tab and swipes those 2 links.
My redirect Link is: http://localhost/shopify/app1/new_prj/install.php
I don't know what is the problem.
It looks like you may have an SSL problem and a redirect problem. Fix this first. I was never able to successfully use localhost or a self signed cert. You need HTTPS
How to make my app embeddable and public not listed?
I would like to add a javascript to the theme/store. Any example?
I would need some help :S
Embedded as in JS loads your App? If so you can have your app add a js script tag to the theme which loads your app js. Then js can talk to your server and get content or data. As for public not listed, just give your app users the install URL. No need to list in the App marketplace.
here is the docs https://help.shopify.com/api/reference/scripttag here is an example but it is using a C# library and not php. https://nozzlegear.com/blog/the-developers-guide-to-shopify-script-tags
but i'm getting this error
Oauth error invalid_request: The redirect_uri is missing or not whitelisted
After i enter:
https://xxxxxxxxx.herokuapp.com/install.php?shop=ecommerce-52.myshopify.com
Please help me with this.