dr9379 2019-01-15 20:00
浏览 41

Spotify授权api并订阅mailchimp

Im trying to get people to authorize with spotify and then subscribe their email to a Mailchimp list.

I got two pieces of code that i need to tie together:

  1. The spotify authorize (which works since i am able to make them follow a user)

          if($_SESSION['accessToken']){
    
          require 'vendor/autoload.php';
          $api = new SpotifyWebAPI\SpotifyWebAPI();
          $api->setAccessToken($_SESSION['accessToken']);
          $following = $api->followArtistsOrUsers('artist', '####');
          $me = $api->me();
          echo $me->email;
    

    At the end I retrieve the users e-mail adres with this piece of code that should be right:

$me = $api->me(); echo $me->email;

The second piece of code is the subscribe to mailchimp

  1. mailchimp subscribe:

this one works, im able to subscribe testmail@test.com to the right list.

<?php 
          $email = 'testmail@test.com';
          $list_id = '#####';
          $api_key = '####';

          $data_center = substr($api_key,strpos($api_key,'-')+1);

          $url = 'https://'. $data_center .'.api.mailchimp.com/3.0/lists/'. $list_id .'/members';

          $json = json_encode([
              'email_address' => $email,
              'status'        => 'subscribed', //pass 'subscribed' or 'pending'
          ]);

          $ch = curl_init($url);
          curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $api_key);
          curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_TIMEOUT, 10);
          curl_setopt($ch, CURLOPT_POST, 1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
          $result = curl_exec($ch);
          $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
          curl_close($ch);
          echo $status_code;
      }
   ?>

However, i seem to be unable to subscribe the e-mail retrieved from spotify to the mailchimplist using I tried:

if($_SESSION['accessToken']){      
require 'vendor/autoload.php';
      $api = new SpotifyWebAPI\SpotifyWebAPI();
      $api->setAccessToken($_SESSION['accessToken']);
      $following = $api->followArtistsOrUsers('artist', '####');
      $me = $api->me();
      echo $me->email;
$email = $me->email;
          $list_id = '#####';
          $api_key = '####';

etc. etc.

can you guys help me out?

Thank you! Sidenote: im just starting out with code, sorry for my rookie level :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题