在shopify中使用API创建webhook(Create a webhook using API in shopify)
在这里,我坚持通过API创建webhook
我正在使用cake php来创建公共shopify应用程序
现在我想使用API为我的应用程序创建carts / update hook这里是我的代码Cake php库: https : //github.com/cmcdonaldca/CakePHP-Shopify-Plugin
文件: ShopifyApiComponent.php
代码:
public function createwebhook($shop_domain, $access_token){ $method = "POST"; $path = "/admin/webhooks.json"; $params = array("webhook" => array( "topic"=>"carts/create", "address"=> $this->site_url."users/upUpdateCart", "format"=> "json")); $password = md5($this->secret.$access_token);//If your shopify app is public $baseurl = "https://".$this->api_key.":".$password."@".$shop_domain."/"; $url = $baseurl.ltrim($path, '/'); $query = in_array($method, array('GET','DELETE')) ? $params : array(); $payload = in_array($method, array('POST','PUT')) ? stripslashes(json_encode($params)) : array(); $request_headers = in_array($method, array('POST','PUT')) ? array("Content-Type: application/json; charset=utf-8", 'Expect:') : array(); $request_headers[] = 'X-Shopify-Access-Token: ' . $access_token; list($response_body, $response_headers) = $this->Curl->HttpRequest($method, $url, $query, $payload, $request_headers); $this->last_response_headers = $response_headers; $response = json_decode($response_body, true); if (isset($response['errors']) or ($this->last_response_headers['http_status_code'] >= 400)) $body = $response['errors']; else $body = $response_body; /*Debug the output in a text_file*/ $destination = realpath('../../app/webroot/execution_log') . '/'; $fh = fopen($destination."shopify_app.txt",'a') or die("can't open file"); date_default_timezone_set('GMT'); fwrite($fh, "\n\nDATE: ".date("Y-m-d H:i:s")."\n".$body); fclose($fh); /*Debug Code Ends*/ return (is_array($response) and (count($response) > 0)) ? array_shift($response) : $response; }
当我访问我的应用程序仪表板时,我调用了此功能,这意味着控制器:提供功能:仪表板
但它似乎没有用,因为当我访问https://test.myshopify.com/admin/webhooks.json时它只显示如果我通过Admin-> Setting-> Notification创建webhook然后它显示在这里列出https:/ /test.myshopify.com/admin/webhooks.json
请告诉我们如何使用API(cake php)创建webhook
Here I stuck in shopify creating webhook through API
I am using cake php for creating public shopify app
Now I would like to create carts/update hook for my app using API here is my code Cake php library : https://github.com/cmcdonaldca/CakePHP-Shopify-Plugin
File : ShopifyApiComponent.php
CODE :
public function createwebhook($shop_domain, $access_token){ $method = "POST"; $path = "/admin/webhooks.json"; $params = array("webhook" => array( "topic"=>"carts/create", "address"=> $this->site_url."users/upUpdateCart", "format"=> "json")); $password = md5($this->secret.$access_token);//If your shopify app is public $baseurl = "https://".$this->api_key.":".$password."@".$shop_domain."/"; $url = $baseurl.ltrim($path, '/'); $query = in_array($method, array('GET','DELETE')) ? $params : array(); $payload = in_array($method, array('POST','PUT')) ? stripslashes(json_encode($params)) : array(); $request_headers = in_array($method, array('POST','PUT')) ? array("Content-Type: application/json; charset=utf-8", 'Expect:') : array(); $request_headers[] = 'X-Shopify-Access-Token: ' . $access_token; list($response_body, $response_headers) = $this->Curl->HttpRequest($method, $url, $query, $payload, $request_headers); $this->last_response_headers = $response_headers; $response = json_decode($response_body, true); if (isset($response['errors']) or ($this->last_response_headers['http_status_code'] >= 400)) $body = $response['errors']; else $body = $response_body; /*Debug the output in a text_file*/ $destination = realpath('../../app/webroot/execution_log') . '/'; $fh = fopen($destination."shopify_app.txt",'a') or die("can't open file"); date_default_timezone_set('GMT'); fwrite($fh, "\n\nDATE: ".date("Y-m-d H:i:s")."\n".$body); fclose($fh); /*Debug Code Ends*/ return (is_array($response) and (count($response) > 0)) ? array_shift($response) : $response; }
and I called this function when I visit my app dashboard mean Controller : Offers function :dashboard
But its not seems to work because when I visit https://test.myshopify.com/admin/webhooks.json its showing nothing but If I am creating webhook through Admin->Setting->Notification then it show listing here https://test.myshopify.com/admin/webhooks.json
Please let me know how we can create webhook using API (cake php )
原文:https://stackoverflow.com/questions/44495615
最满意答案
尝试将委托发送到nextviewcontroller
DestinationViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"DestinationViewController"]; controller.args=myArgs; controller.delegate = self; [self.navigationController pushViewController:controller animated:YES];
当从该viewController返回到当前表视图控制器时,通过该委托。
这可能会帮助你...
Try sending a delegate to the nextviewcontroller like
DestinationViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"DestinationViewController"]; controller.args=myArgs; controller.delegate = self; [self.navigationController pushViewController:controller animated:YES];
and when traversing back from that viewController to the present table viewcontroller pass that delegate.
This may help you...
相关问答
更多-
您将某些内容直接分配给弱引用,并且此时没有强大的拥有引用,因此立即删除弱引用。 当你在下一行访问它时,你的命中率为零! ,这会导致你的崩溃。 您需要创建一个局部变量,该变量将标签保留在范围内,直到其他东西保留它为止,例如您将其添加到视图中: func didLoad() { let label = UILabel() // Configure the label... self.view.addSubview(label) // A view retains its subv ...
-
因为您已经有一系列条目,所以您也可以编写如下。 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Entry *entry = [self.entries objectAtIndex:[indexPath row]]; } 我认为这比cellForRowAtIndexPath更受欢迎:因为 你可以得到整个入口对象,而不仅仅是ID。 你可以像字符串一样使用非整数I ...
-
你可以得到Date : 04/20 let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZZZ" let Date = dateFormatter.dateFromString("2016-04-20 06:00:00 +0000") dateFormatter.dateFormat = "MM/dd" let newDate = dateF ...
-
这是因为你在iOS < 7.0使用它。 如果你可以在文档中看到它,你会发现这个NS_CLASS_AVAILABLE(10_9, 7_0) ,这意味着它在iOS 7.0可用。 所以我建议你使用运行iOS 7模拟器或设备 It's because you are using this for iOS < 7.0. If you can see it in docs you will find this NS_CLASS_AVAILABLE(10_9, 7_0) which means that it's ava ...
-
NSIndexPath - 如何?(NSIndexPath - how to?)[2021-07-27]
至于旁边的列表,请使用UITableViewDataSource方法sectionIndexTitlesForTableView: 请记住,它只适用于使用UITableViewStylePlain As for the list on the side, use the UITableViewDataSource method sectionIndexTitlesForTableView: Keep in mind it only works if you're using UITableViewStyle ... -
在定义之后你没有设置任何image ,所以它在这里将是nil : var image = UIImageView? 当你强行打开它! 在这里,你遇到了运行时错误: image!.image = result You aren't setting anything to image after defining it, so it's going to be nil here: var image = UIImageView? When you force-unwrap it with ! her ...
-
NSIndexPath返回nil(NSIndexPath return nil)[2022-09-20]
尝试将委托发送到nextviewcontroller DestinationViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"DestinationViewController"]; controller.args=myArgs; controller.delegate = self; [self.navigationController pushViewCo ... -
假设您正在使用故事板,并且如果您愿意更改方法,那么您正在使用可能的解决方案(在我看来,这是一个更清洁的解决方案): 将单元格内UICollectionView的出口UICollectionView UITableViewCell 。 在您的故事板中再次通过拖动插座将UICollectionView的delegate和dataSource设置到您的类。 当然,您必须使用自定义UITableViewCell 在用于UITableView的cellForRowAtIndexPath中,将UICollectionV ...
-
在创建CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)imageURL, NULL); 我只是忘了指定图像的属性。 以下是CGImageSourceCreateWithURL的以下工作代码 NSURL *imageURL = [self getImageAtTime:i withTitle:@"gifImage"]; if (!imageURL) { ...
-
让表视图决定是否需要更新单元格。 只需删除代码中的所有第一部分,一切都将顺利进行。 不要犹豫,阅读UITableView文档。 Let the table view decide id it need to update the cell or not. Just remove all the firsdt part of your code and everything will run smoothly. Don't hesitate to read the UITableView doc.