How to get google adwords reports in salesforce? - salesforce

Hi I am developing application in salesforce for accessing the google adwords reports data for e.g. ADGROUP_PERFORMANCE_REPORT. I am sending http post request to https://adwords.google.com/api/adwords/reportdownload/v201302, and I am using apex(java like language in salesforce) below is my request.
Http h = new Http();
HttpRequest req = new HttpRequest();
GoogleAuthorization auth=new GoogleAuthorization();
req.setHeader('Authorization', 'GoogleLogin ' + auth.token);
req.setHeader('UserAgent', 'XXXXX');
req.setHeader('developerToken','XXXXXXXX');
req.setHeader('clientCustomerId','XXXXXXXX');
req.setEndPoint('https://adwords.google.com/api/adwords/reportdownload/v201302');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
req.setMethod('POST');
string xml='<reportDefinition xmlns="https://adwords.google.com/api/adwords/cm/v201302">'+
'<selector>'+
'<fields>CampaignId</fields>'+
'<fields>Id</fields>'+
'<fields>Impressions</fields>'+
'<fields>Clicks</fields>'+
'<fields>Cost</fields>'+
'<predicates>'+
'<field>Status</field>'+
'<operator>IN</operator>'+
'<values>ENABLED</values>'+
'<values>PAUSED</values>'+
'</predicates>'+
'</selector>'+
'<reportName>Custom Adgroup Performance Report</reportName>'+
'<reportType>ADGROUP_PERFORMANCE_REPORT</reportType>'+
'<dateRangeType>LAST_7_DAYS</dateRangeType>'+
'<downloadFormat>XML</downloadFormat>'+
'</reportDefinition>';
req.setBody('__rdxml='+EncodingUtil.urlEncode(xml, 'UTF-8'));
HttpResponse res=h.send(req);
After requesting i am getting the AuthenticationError System.HttpResponse[Status=Bad Request, StatusCode=400].
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><reportDownloadError><ApiError><type>AuthenticationError.USER_ID_INVALID</type><trigger><null></trigger><fieldPath></fieldPath></ApiError></reportDownloadError>
However my loginid and password is correct. What i am doing wrong can anybody please help!

Check your app's configuration.
You must have there something like this :
<AdWordsApi>
<add key="MaskCredentials" value="true" />
<add key="EnableGzipCompression" value="true" />
<add key="ProxyServer" value="" />
<add key="ProxyUser" value="" />
<add key="ProxyPassword" value="" />
<add key="ProxyDomain" value="" />
<add key="UserAgent" value="*******" />
<add key="DeveloperToken" value="*******" />
<add key="ClientCustomerId" value="*******" />
<add key="SkipReportHeader" value="false" />
<add key="SkipReportSummary" value="false" />
<add key="OAuth2ClientId" value="*******" />
<add key="OAuth2ClientSecret" value="*******" />
<add key="OAuth2Mode" value="APPLICATION" />
<add key="OAuth2RefreshToken" value="1/*******" />
</AdWordsApi>
fill all required values *****.

Related

Azure Redirect URI showing directory path

I Created web application using azure authentication. I created app registration with secrets key.
Its working fine while debugging but After publish the project in localhost its won't working. its showing folder dir path only.
My Code
if (Request.IsAuthenticated)
{
Response.Redirect("default.aspx",false);
}
else
{
HttpContext.Current.GetOwinContext().Authentication.Challenge(new
AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
Web Config
<add key="ida:GraphResourceId" value="https://graph.microsoft.com" />
<add key="ida:GraphUserUrl" value="https://graph.microsoft.com/{0}/me?api-version=2013-11-08" />
<add key="todo:TodoListResourceid" value="api://xxxxxxxxxxx" />
<add key="todo:TodoListBaseAddress" value="http://localhost/Test/" />
<add key="ida:ClientId" value="xxxxxxx" />
<add key="ida:AppKey" value="xxxxxxxxx" />
<add key="ida:Tenant" value="aaaaaaaaaaa" />
<add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" />
<add key="ida:RedirectUri" value="http://localhost/Test" />
Error Image :

log4net logger logging unexpected levels based on config

I have been trying to understand the config of the log4net library and I think I have it except for some unexpected behavior.
I have a root logger that has a level set to INFO and another logger for a specific class that has level set to ERROR.
What I expected from this was that the class logger would only log at error and ignore the roots level since I had additivity set to false for the class logger. Here is the log4net.config I have at the moment:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<logger name="EveStatic.Config.ViewModel" additivity="false">
<level value="error"/>
<appender-ref ref="ConsoleAppender"/>
<appender-ref ref="RollingFileAppender"/>
</logger>
<root>
<level value="debug" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
</configuration>
In my AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
And in the class that loads the configuration:
log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config"));
These two seem redundant but the configuration wont load unless I have the code part. Everything here is in a class library being used by another project.
Is this behavior expected and I don't understand the configuration and level overrides or am I forgetting something?
EDIT:
Here is how I instantiate and call the ILog. The the full class name is the name of the logger in the config plus the ConfiInfoViewModel:
private static readonly ILog LOG = LogManager.GetLogger(typeof(ConfigInfoViewModel));
...
LOG.Debug("Something buggy");
Also note that when testing the logging levels I had a log statement for each level in a series.
Your problem lays here
LogManager.GetLogger(typeof(ConfigInfoViewModel));
Internally this get resolved to
LogManager.GetLogger(typeof(ConfigInfoViewModel).FullName);
Now log4net is looking for a Logger named "EveStatic.Config.ConfigInfoViewModel" (result of typeof(ConfigInfoViewModel).FullName)
Because no Logger with that name is specified a new one with your default settings is used.
Also note that level specify a threshold, not a single level.
Example: level=warn means log warn an all levels above (error and fatal)

WPF log4net is not writing to the log file [duplicate]

This question already has an answer here:
WPF-Log4Net used inside VSIX extension did not output log when installed at target VS
(1 answer)
Closed 4 years ago.
I have a WPF solution. I downloaded log4net dll, I added log4net.config and had set the "Copy to Output Directory" value as "Copy always".
log4net.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="myapp.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
And I added the below line in AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
then the below code in my TestWindowControl.xaml.cs
public partial class TestWindowControl : UserControl
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public TestWindowControl()
{
XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
log.Info("info testing");
log.Debug("debug testing");
log.Error("error testing");
log.Fatal("fatal testing");
log.Warn("warn testing");
}
}
But logs are not writing to the file. It's working in Console application but not working for WPF. Am I missing something?
Try to set the filter inside appender
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="WARN" />
<levelMax value="ERROR" />
</filter>

AngularJS and URL Rewrite to HTTPS

So I have ui-router in my application and everything has been working fine.
I was asked to make the account area of the site forced HTTPS so I set up this rule:
I have a link on the main "view" that takes you to the login page and the link looks just like this:
<a class="link-primary" ui-sref="login" ng-switch-default>Sign in</a>
The state rule set up looks like this:
.state('login', {
url: '/account/signin',
params: {
returnState: null,
returnParams: null
},
templateUrl: '/assets/tpl/account/signin.tpl.html',
controller: 'LoginController',
controllerAs: 'controller',
resolve: {
pageTitle: ['PageHead', function (service) {
service.setTitle('Kudos Sports - Login');
}]
}
})
When I click the link I get an error message:
XMLHttpRequest cannot load https://kudos-topspindigital.azurewebsites.net/assets/tpl/account/signin.tpl.html. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://kudos-topspindigital.azurewebsites.net' is therefore not allowed access.
I can type the url (https://kudos-topspindigital.azurewebsites.net/account/signin) and this works without any issues. I can even do it by omitting the https protocol and it will redirect with no issues, so I can only assume there is something wrong with angularJS.
Can someone help me fix my issue?
Try add HTTP header in your server response by:
"Access-Control-Allow-Origin", "*"
This time, use server side script to return HTML instead pure html, for example, in PHP
<?php
header("Access-Control-Allow-Origin: *");
Tbh the best way for me to do this was to set up a rule that pushed everything to HTTPS, not just the account stuff.
<rule name="Redirect .com to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="kudos-sports.co.uk" />
<add input="{HTTP_HOST}" pattern="kudos-sports.com" />
<add input="{HTTP_HOST}" pattern="kudos-sportswear.co.uk" />
<add input="{HTTP_HOST}" pattern="kudos-sportswear.com" />
<add input="{HTTP_HOST}" pattern="www.kudos-sports.co.uk" />
<add input="{HTTP_HOST}" pattern="www.kudos-sportswear.co.uk" />
<add input="{HTTP_HOST}" pattern="www.kudos-sportswear.com" />
<add input="{HTTP_HOST}" pattern="kudos-sports.azurewebsites.net" />
</conditions>
<action type="Redirect" url="https://www.kudos-sports.com{REQUEST_URI}" />
</rule>

After successful LDAP authentication takes to login

I am new spring-security I did spring authentication with ActiveDirectory, It was working after adding
<beans:bean id="myauthenticationrpovider" class="com.holcim.acl.rm.security.MyAuthoritySupplementingProvider">
<beans:constructor-arg ref="ldapActiveDirectoryAuthProvider" />
and bean code as follows
public class MyAuthoritySupplementingProvider implements AuthenticationProvider {
private AuthenticationProvider delegate;
public MyAuthoritySupplementingProvider(AuthenticationProvider delegate) {
this.delegate = delegate;
}
public Authentication authenticate(Authentication authentication) {
final Authentication a = delegate.authenticate(authentication);
//get first username and full User Name from a i.e Authentication.
Object auth = a.getPrincipal();
String username;
String userFullName;
if(auth instanceof LdapUserDetailsImpl){
LdapUserDetailsImpl userDetails = (LdapUserDetailsImpl) auth;
String[] dn = userDetails.getDn().split(",");
String[] temp = dn[0].split("=");
userFullName = temp[1];
username = ((LdapUserDetailsImpl) auth).getUsername();
logger.debug("AD Authentication done ");
logger.debug(userDetails.getDn());
logger.debug("User Full Name " + temp[1]);
logger.debug("UserName is :: "+ username);
}
// Load additional authorities and create an Authentication object
//final List<GrantedAuthority> authorities = loadRolesFromDatabaseHere();
List<AclAuthority> authorities = new ArrayList<AclAuthority>();
authorities.add(AclAuthority.ROLE_ADMIN);
return new AbstractAuthenticationToken(authorities) {
public Object getCredentials() {
throw new UnsupportedOperationException();
}
public Object getPrincipal() {
return a.getPrincipal();
}
};
}
#Override
public boolean supports(Class<?> authentication) {
return delegate.supports(authentication);
}
}
application-security.xml as follows
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<!-- HTTP security configurations -->
<http auto-config="true" use-expressions="true">
<form-login login-processing-url="/static/j_spring_security_check" login-page="/login" authentication-failure-url="/login?login_error=t" />
<logout logout-url="/static/j_spring_security_logout" />
<!-- Configure these elements to secure URIs in your application -->
<intercept-url pattern="/choices/**" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/member/**" access="isAuthenticated()" />
<intercept-url pattern="/resources/**" access="permitAll" />
<intercept-url pattern="/static/**" access="permitAll" />
<intercept-url pattern="/login/**" access="permitAll" />
<intercept-url pattern="/**" access="isAuthenticated()" />
</http>
<!-- Active directory authentication added by Kamlesh A. -->
<!-- LDAP server details -->
<authentication-manager>
<authentication-provider ref="myauthenticationrpovider" />
</authentication-manager>
<beans:bean id="ldapActiveDirectoryAuthProvider" class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
<beans:constructor-arg value="in.mycompany.net" />
<beans:constructor-arg value="ldap://XXX.XXX.XXX.XXX:PPP" />
<!--<beans:property name="authoritiesMapper" ref="grantedAuthoritiesMapper" />-->
<beans:property name="useAuthenticationRequestCredentials" value="true" />
<beans:property name="convertSubErrorCodesToExceptions" value="true" />
</beans:bean>
<beans:bean id="myauthenticationrpovider" class="com.holcim.acl.rm.security.MyAuthoritySupplementingProvider">
<beans:constructor-arg ref="ldapActiveDirectoryAuthProvider" />
</beans:bean>
</beans:beans>
I have gone through so questions
Spring Security redirect to previous page after successful login
as well as
Unexpected redirect to login page after successful login
after successfull login it takes to
http://localhost:8080/static/j_spring_security_check
But if I try to open anyother url it again take to login

Resources