首页 \ 问答 \ 在shopify中使用API创建webhook(Create a webhook using API in shopify)

在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
更新时间:2024-03-07 14:03

最满意答案

尝试将委托发送到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 ...
  • 至于旁边的列表,请使用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 ...
  • 尝试将委托发送到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.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)