Twitter Tailored Audiences User - twitter

I am using this api end to post user in audience list id(which i am creating dynamically).
Here is code i am using -:
require '../vendor/autoload.php';
require 'config.php';
$api = TwitterAds::init(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
$responseAcc = $api->get('accounts');
$account = $responseAcc->getBody();
$twAdsAccId = $account->data[0]->id;
$response = $api->post('accounts/'.$twAdsAccId.'/tailored_audiences',array('name'=>'Test'));
$newAudiDat = $response->getBody();
$audienceId = $newAudiDat->data->id;
$userJson = '{
{
"users": [
{
"email": [
"c88a2aba7408c019ea7e721832cc89aeec2f91169872a977fbbe46d642c8fdd9"
]
}
]
}
}';
$responseAudieUser =$api->post('accounts/'.$twAdsAccId.'/tailored_audiences/'.$audienceId.'/users',array('operation_type'=>'Update','params'=> $userJson));
But when I am printing the response it is showing error :-
caught exception 'Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError' with message 'SERVER_ERROR' in /opt/lampp/htdocs/demo/tweets-php/vendor/hborras/twitter-php-ads-sdk/src/TwitterAds.php:501
I think I am passing parameter in wrong way so i searched but did not get any lead .
Note -: All parameters are sent in the request body and a Content-Type of application/json is required (Please see).

Here Hector, maintainer of this project
Could you create a new Issue here : https://github.com/hborras/twitter-php-ads-sdk/issues ?
Meantime I'll try to see what is happening
Thanks!

Related

I'm unable to get my API token using the below POST code

I am trying to get a authentication token using this code below, i am kind of confused on how to go about it.
url = "https://api.tradingcentral.com/authentication/v3"
headers = {"accept: application/json",
"Content-Type: application/json"}
data = {"clientId": "rc-xxx", "password": "4xxxxxxxxxx", "endUserId": "testuserid", "admin": 'false'}
response = requests.post(url = url, headers=headers, params=data)
df = response.text
I seem to be doing something wrong.

Keep getting Twilio error message 90100 on execution, but results are working

I'm not a programmer so please forgive me. But I've spent hours and hours of research on the topic of collecting information with Twilio AutoPilot and posted that data to Airtable, which I will then have Zapier do some things with that data. I finally had a breakthrough today and am now able to post data from a call or text to Airtable. The only way I got the ending to work was to send the call or text to Studio to finish up the call. Everything seems to work from the end user standpoint, but I'm getting an error 90100 from Twilio. I'm sure I'm just missing one line of code for this to work, and I'm at the end of my rope.
{
"actions": [
{
"say": "Okay lets get you a new appointment. I just need you to answer a few questions."
},
{
"collect": {
"name": "member",
"questions": [
{
"question": "Please tell me your first name.",
"name": "name",
"type": "Twilio.FIRST_NAME"
},
{
"question": "Thanks, and what is your email address?",
"name": "email",
"type": "Twilio.EMAIL"
}
],
"on_complete": {
"redirect": "task://complete_booking"
}
}
}
]
}
Then i have another task setup to redirect to the Twilio Function. This is probably overkill, but it's what I found in research.
{
"actions": [
{
"redirect": {
"method": "POST",
"uri": "https://TWILIO_FUNCTION_URL/atable_post"
}
}
]
}
Then the function is as follows. Mind you, this is posting correctly to airtable.
exports.handler = function(context, event, callback) {
let memory = JSON.parse(event.Memory);
let name = memory.twilio.collected_data.member.answers.name.answer;
let email = memory.twilio.collected_data.member.answers.email.answer;
console.log(memory);
let member = {
name : memory.twilio.collected_data.member.answers.name.answer,
email : memory.twilio.collected_data.member.answers.email.answer,
date : Date.now()
};
var Airtable = require("airtable");
var base = new Airtable({apikey: context.AIRTABLE_API_KEY}).base("AIRTABLE_ID");
base("Members1").create(member, function(err, record) {
if (err) { console.error(err); return; }
console.log(record.getId());
callback(null, member);
});
};
The call hung up at this point, so I redirected it to a Studio Flow, which does work and the call finishes with the response I'm give it before ending the call. Again, everything is working fine, but I get the following error from twilio, and I have no idea how to resolve it.
Invalid Autopilot Actions JSON: Invalid Autopilot Action
Any help would be greatly appreciated. Thanks!
Nice work James! It looks the the issue is the redirect to your Twilio Function is not returning the expected JSON Action response to execute.
Autopilot - Redirect
https://www.twilio.com/docs/autopilot/actions/redirect
Redirecting to URLs When redirecting to a URL, Redirect will make an
HTTP callback to your application and will expect an Autopilot Actions
JSON as a response. The request will contain all the dialogue
information. This is an example of a dynamic Action since the JSON is
rendered dynamically with a URL or your own endpoint.
Can you modify the Twilio Function to return valid Action JSON to Autopilot which sets the returned data, if needed via the Remember action which you can access from Studio?

Why the "Authorization" field in Http Headers in Alamofire set automatically?

I want to send my apiKey in headers in Alamofire to my web service.But no matter how many times I test it,I still cant to get the value of apiKey in my web service.
My web service always return this error,cause cant get the apiKey in the header.
{
"error": true,
"message": "Api key is missing"
}
This is how I make the request,I think I didnt do anything wrong,but the web service still cant get the value of apiKey.
let My_URL = "My_url"
let params : [String : Any]=["param1":value1,"param2":value2]
let headers : HTTPHeaders = [
"Content-Type":"application/x-www-form-urlencoded",
"authorization" : apiKey //<--this is the value I need to
get in header of web service
]
Alamofire.request(MY_URL,method: .post ,parameters : params ,headers:headers).responseJSON {
response in
debugPrint(response)
}
My web service currently is serving for Android and Web version.Both running well,but I really no idea why the ApiKey in headers cant get it from webservice.
Totally no idea what is going wrong..Somebody please help!!!!
EDIT
I attach the result from debugPrint here,please take a look and let me know what is the problem,I suspect the problem is cause by the "Authorization" tag in the result below,the "Authorization" field is not the field I set,and the value as well,is not the value I want as well.
But why is this happen?? And how to solve this problem?
[Response]: <NSHTTPURLResponse: 0x60c00003d4c0> { URL: http://My_URL} { Status Code: 400, Headers {
"Access-Control-Allow-Headers" = (
Authorization
);
"Access-Control-Allow-Methods" = (
"GET, POST, PUT, DELETE, OPTIONS"
);
"Access-Control-Allow-Origin" = (
"*"
);
Authorization = ( // <--why this authorization appear
16ebe49c51039ddfbb09e5df8519e755 //this is not the value I set
);
Connection = (
close
);
"Content-Length" = (
45
);
"Content-Type" = (
"application/json"
);
Date = (
"Sun, 14 Dec 2017 14:20:59 GMT"
);
Server = (
"Apach(Ubuntu)"
);
"X-Powered-By" = (
"PHP/5.5.9-1"
);
} }
EDIT:
To solve the problem above,I read this following question
iOS Alamofire Incorrect Authorization Header
How to disable the URLCache completely with Alamofire
Therefore,I modify my request as below,but the problem still the same,the result of debugPrint is still same as above.
let configuration = URLSessionConfiguration.default
configuration.urlCache = nil
let sessionManager = Alamofire.SessionManager(configuration: configuration)
let params : [String : Any]=["param1":value1,"param2":value2]
let headers : HTTPHeaders = [
"Content-Type":"application/x-www-form-urlencoded",
"authorization" : apiKey //<--this is the value I need to
get in header of web service
]
sessionManager.request(MY_URL,method: .post ,parameters : params ,headers:headers).responseJSON {
response in
debugPrint(response)
}.session.finishTasksAndInvalidate()
I know this question was asked long time ago, but to solving other persons issue I answer it.
Removing Authorization header value is not a bug make by alamofire lib. This key and some other keys are NSURLSession reserved key, so according to apple document value of these keys may change. To avoid this issue you must change the header name to something like Authorization-App or any other key confirmed by your API team.

How to create a task in asana with bold description?

I am able to create Project / task / attachment fine with Asana API with PHP.
Is there a way to create Bold for Emphasis description for task / project ?
I could not find that in Asana API.
Can someone point me to right direction?
I can confirm that if you send in html_notes instead of notes you will be able to use SOME html tags. The html tags that is valid is not documented, so you will have to test to find working tags.
"html_notes": "<strong>This will be bold in Asana</strong>"
I used the following with success when creating a task within a Workspace and a project. Note that this is using WebRequest in a ASP.NET WebApi (C#). But the Json string should work just fine with your project :)
IMPORTANT: Do not encode the html before POST.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://app.asana.com/api/1.0/tasks");
httpWebRequest.Method = "POST";
httpWebRequest.PreAuthenticate = true;
httpWebRequest.Headers.Add("Authorization", "Bearer <PERSONAL_TOKEN>");
httpWebRequest.ContentType = "application/json";
string json = "{\"data\": {\"workspace\": \"123456789\",\"html_notes\": \"<strong>" + question.Message + "</strong>\",\"name\": \"" + Username + "\",\"projects\": \"123456789\"}}";
using (StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream()))
{
sw.Write(json);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
A simple way using ASANA API's use this..
URL : https://app.asana.com/api/1.0/tasks
Method : POST
HEADER : Authorization:Bearer <your token>
Content-Type:application/json
Accept:application/json
Body :
{
"data": {
"approval_status": "pending",
"assignee": "1111----572318",
"assignee_status": "upcoming",
"due_on": "2019-09-15",
"followers": [
"31441----023","1617----554125"
],
"html_notes": "<body>Looking how can i create task under a <strong>project</strong></body>",
"name": "Task created form Postman - 3",
"workspace": "11288-----8660",
"projects":["1185----23561"]
}
}
Sample

Laravel 5 dingo api, add multiple transformed objects to the response

Want to add a transformed object along with other response, I have used following code:
$accessToken = Authorizer::issueAccessToken();
$user = User::where('email', $request->get('username'))->with('profile')->first();
if ($user) {
$accessToken['user'] = $this->response->item($user, new UserTransformer);
}
return $accessToken;
Expected Response:
{
"access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"token_type": "Bearer",
"expires_in": 31536000,
"data": {
"id": 1,
"email": "xxxxx",
"profile": {
"data": {
"id": 1,
"first_name": "Muhammad",
"last_name": "Shakeel",
}
}
}
}
but not getting transformed object, there must be some better way to add multiple transformed objects with response. Am I missing something?
Edit
Current response returns user object without transformation and if I return only user transformed object like following, it returns correct transformed object:
return $this->response->item($user, new UserTransformer);
As discussed on the issue tracker(https://github.com/dingo/api/issues/743#issuecomment-160514245), jason lewis responded to the ticket with following:
The only way you could do this at the moment would be to reverse that. So you'd return the response item, then add in the access token data, probably as meta data.
So, something like this.
return $this->response->item($user, new UserTransformer)->setMeta($accessToken);
The response will then contain a meta data key which will contain your access token data.
I got it to work using Internal Requests. https://github.com/dingo/api/wiki/Internal-Requests
So what you can do is
Suppose you have a route that fetches transformed user object at api/users/{email_id}?access_token=...
While issuing the access_token you can do the following :
$dispatcher = app('Dingo\Api\Dispatcher');
$array = Authorizer::issueAccessToken();
$array['user'] = $dispatcher->get('api/users/'.$request->get("username").'?access_token='.$array['access_token']);
return $array;
This will return transformed data.
NOTE : You will need to have a route that fetches user data.
You will have to handle cases in /api/users/{email-id} where email-id does not exist.

Resources